package com.xmy.cultivate.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.xmy.cultivate.entity.*;
import com.xmy.cultivate.entity.response.ArrivalRate;
import com.xmy.cultivate.entity.views.*;
import com.xmy.cultivate.feign.ITeacherFeignClient;
import com.xmy.cultivate.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@Service
public class IntegralStatisticsServiceImpl implements IIntegralStatisticsService {

    @Autowired
    ISenateSubjectsProjectsService iSenateSubjectsProjectsService;

    @Autowired
    ITeacherFeignClient iTeacherFeignClient;

    @Autowired
    ISenateScoreService iSenateScoreService;

    @Autowired
    IRecordCourseService iRecordCourseService;

    @Autowired
    ISenateDepartProjectsService iSenateDepartProjectsService;

    @Autowired
    ISenateDepartService iSenateDepartService;

    @Autowired
    ISenateDepartScoreSetService iSenateDepartScoreSetService;

    @Autowired
    ITrackMarketService iTrackMarketService;

    @Autowired
    IRadeFiducialService iRadeFiducialService;

    @Autowired
    IRadeFiducialSetService iRadeFiducialSetService;


    static class RankedArrivalRate {
        private Long schoolId;
        private BigDecimal rade;

        public RankedArrivalRate(Long schoolId, BigDecimal rade) {
            this.schoolId = schoolId;
            this.rade = rade;
        }

        public Long getSchoolId() {
            return schoolId;
        }

        public BigDecimal getRade() {
            return rade;
        }
    }

    // 默认年级
    static final String YEAR_CLASS_ID_DEFAULT = "0,1,2,3,4,5,6,7,8,9";

    // 包含高中年级
    static final String YEAR_CLASS_ID_INCLUDE = "0,1,2,3,4,5,6,7,8,9,10,11,12";

    /**
     * 个人教务积分统计（新）
     */
    @Override
    public void integralStatisticsActionNew(IntegralStatisticsRs integralStatisticsRs) {
        Integer yearPart = integralStatisticsRs.getYearPart();
        Integer quarterNum = integralStatisticsRs.getQuarterNum();
        String teacherId = null;
        if (integralStatisticsRs.getTeacherId() != null) {
            teacherId = integralStatisticsRs.getTeacherId().toString();
        }
        Integer startLessonNum = 0;
        Integer endLessonNum = 0;

        if (integralStatisticsRs.getStartLessonNum() != null && integralStatisticsRs.getEndLessonNum() != null) {
            startLessonNum = integralStatisticsRs.getStartLessonNum();
            endLessonNum = integralStatisticsRs.getEndLessonNum();
        } else {
            Integer lessonMax = iRecordCourseService.getMaxLessonNumForInClass(yearPart, quarterNum, 1);
            if (lessonMax != null) {
                startLessonNum = 1;
                endLessonNum = lessonMax;
            }
        }

        QueryWrapper<SenateDepartScoreSet> senateDepartScoreSetQueryWrapper = new QueryWrapper<>();
        senateDepartScoreSetQueryWrapper.eq("year_part", yearPart);
        senateDepartScoreSetQueryWrapper.eq("quarter_num", quarterNum);
        senateDepartScoreSetQueryWrapper.eq("score_type", 1);
        senateDepartScoreSetQueryWrapper.orderByDesc("senate_project_id");
        List<SenateDepartScoreSet> senateDepartScoreSets = iSenateDepartScoreSetService.list(senateDepartScoreSetQueryWrapper);

        LocalDate dateNow = LocalDate.now();

        for (Integer i = startLessonNum; i <= endLessonNum; i++) {
            for (SenateDepartScoreSet scoreSet : senateDepartScoreSets) {
                //英语精品课到课率
                if (scoreSet.getTag().equals("英语精品课到课率")) {
                    try {
                        List<ArrivalRate> arrivalRateList = iTeacherFeignClient.arrivalRate(1, null, "1", null, dateNow.toString(), dateNow.toString(), null, null, "2", null, null, yearPart.toString(), quarterNum.toString(), null, null, null, null, "1", null, i.toString(), i.toString(), null, teacherId, "0", "0");
                        for (ArrivalRate arrivalRate : arrivalRateList) {

                            SenateScoreView senateScore = new SenateScoreView();
                            BigDecimal arrivalCount = new BigDecimal(arrivalRate.getArrivedCount());
                            BigDecimal studentAllCount = new BigDecimal(arrivalRate.getStudentAllCount());
                            if (studentAllCount.equals(BigDecimal.ZERO)) {
                                continue;
                            }
                            BigDecimal rade = arrivalCount.divide(studentAllCount, 4, BigDecimal.ROUND_HALF_UP);
                            rade = rade.multiply(new BigDecimal(100));
                            senateScore.setRadeNum(rade);
                            senateScore.setCount(arrivalCount);
                            senateScore.setAllCount(studentAllCount);
                            senateScore.setProjectsId(scoreSet.getSenateProjectId());//到课率
                            senateScore.setLessonNum(i);
                            senateScore.setTeacherId(arrivalRate.getTeacherId());
                            senateScore.setType(1);
                            senateScore.setSubjectsId(arrivalRate.getSubjectsId());
                            senateScore.setYearPart(yearPart);
                            senateScore.setQuarterNum(quarterNum);
                            senateScore.setScoreType(1);// 根据senate_depart_score_set表，1个人，2战队
                            senateScore.setTag("英语精品课到课率");
                            iSenateScoreService.addOrUpdateSenateScoreDataNew(senateScore);
                        }
                    } catch (Exception e) {
                    }
                } else if (scoreSet.getTag().equals("数学精品课到课率")) {
                    // 数学精品课到课率
                    try {
                        List<ArrivalRate> arrivalRateList = iTeacherFeignClient.arrivalRate(1, null, "2", null, dateNow.toString(), dateNow.toString(), null, null, "2", null, null, yearPart.toString(), quarterNum.toString(), null, null, null, null, "1", null, i.toString(), i.toString(), null, teacherId, "0", "0");
                        for (ArrivalRate arrivalRate : arrivalRateList) {

                            SenateScoreView senateScore = new SenateScoreView();
                            BigDecimal arrivalCount = new BigDecimal(arrivalRate.getArrivedCount());
                            BigDecimal studentAllCount = new BigDecimal(arrivalRate.getStudentAllCount());
                            if (studentAllCount.equals(BigDecimal.ZERO)) {
                                continue;
                            }
                            BigDecimal rade = arrivalCount.divide(studentAllCount, 4, BigDecimal.ROUND_HALF_UP);
                            rade = rade.multiply(new BigDecimal(100));
                            senateScore.setRadeNum(rade);
                            senateScore.setCount(arrivalCount);
                            senateScore.setAllCount(studentAllCount);
                            senateScore.setProjectsId(scoreSet.getSenateProjectId());//到课率
                            senateScore.setLessonNum(i);
                            senateScore.setTeacherId(arrivalRate.getTeacherId());
                            senateScore.setType(1);
                            senateScore.setSubjectsId(arrivalRate.getSubjectsId());
                            senateScore.setYearPart(yearPart);
                            senateScore.setQuarterNum(quarterNum);
                            senateScore.setScoreType(1);// 根据senate_depart_score_set表，1个人，2战队
                            senateScore.setTag("数学精品课到课率");
                            iSenateScoreService.addOrUpdateSenateScoreDataNew(senateScore);
                        }
                    } catch (Exception e) {
                    }
                } else if (scoreSet.getTag().equals("物理精品课到课率")) {
                    // 物理精品课到课率
                    try {
                        List<ArrivalRate> arrivalRateList = iTeacherFeignClient.arrivalRate(1, null, "3", null, dateNow.toString(), dateNow.toString(), null, null, "2", null, null, yearPart.toString(), quarterNum.toString(), null, null, null, null, "1", null, i.toString(), i.toString(), null, teacherId, "0", "0");
                        for (ArrivalRate arrivalRate : arrivalRateList) {
                            SenateScoreView senateScore = new SenateScoreView();
                            BigDecimal arrivalCount = new BigDecimal(arrivalRate.getArrivedCount());
                            BigDecimal studentAllCount = new BigDecimal(arrivalRate.getStudentAllCount());
                            if (studentAllCount.equals(BigDecimal.ZERO)) {
                                continue;
                            }
                            BigDecimal rade = arrivalCount.divide(studentAllCount, 4, BigDecimal.ROUND_HALF_UP);
                            rade = rade.multiply(new BigDecimal(100));
                            senateScore.setRadeNum(rade);
                            senateScore.setCount(arrivalCount);
                            senateScore.setAllCount(studentAllCount);
                            senateScore.setProjectsId(scoreSet.getSenateProjectId());//到课率
                            senateScore.setLessonNum(i);
                            senateScore.setTeacherId(arrivalRate.getTeacherId());
                            senateScore.setType(1);
                            senateScore.setSubjectsId(arrivalRate.getSubjectsId());
                            senateScore.setYearPart(yearPart);
                            senateScore.setQuarterNum(quarterNum);
                            senateScore.setScoreType(1);// 根据senate_depart_score_set表，1个人，2战队
                            senateScore.setTag("物理精品课到课率");
                            iSenateScoreService.addOrUpdateSenateScoreDataNew(senateScore);
                        }
                    } catch (Exception e) {
                    }
                /*} else if (scoreSet.getTag().equals("英语智能课到课率")) {
                    // 英语智能课到课率
                    List<ArrivalRate> arrivalRateList = iTeacherFeignClient.arrivalRate(1, null, "1", null, dateNow.toString(), dateNow.toString(), null, null, "2", null, null, yearPart.toString(), quarterNum.toString(), null, null, null, null, "2", null, i.toString(), i.toString(), null, teacherId);
                    for (ArrivalRate arrivalRate : arrivalRateList) {
                        //try {
                        SenateScoreView senateScore = new SenateScoreView();
                        BigDecimal arrivalCount = new BigDecimal(arrivalRate.getArrivedCount());
                        BigDecimal studentAllCount = new BigDecimal(arrivalRate.getStudentAllCount());
                        if (studentAllCount.equals(BigDecimal.ZERO)) {
                            continue;
                        }
                        BigDecimal rade = arrivalCount.divide(studentAllCount, 4, BigDecimal.ROUND_HALF_UP);
                        rade = rade.multiply(new BigDecimal(100));
                        senateScore.setRadeNum(rade);
                        senateScore.setCount(arrivalCount);
                        senateScore.setAllCount(studentAllCount);
                        senateScore.setProjectsId(scoreSet.getSenateProjectId());
                        senateScore.setLessonNum(i);
                        senateScore.setTeacherId(arrivalRate.getTeacherId());
                        senateScore.setType(1);
                        senateScore.setSubjectsId(arrivalRate.getSubjectsId());
                        senateScore.setYearPart(yearPart);
                        senateScore.setQuarterNum(quarterNum);
                        senateScore.setScoreType(1);// 根据senate_depart_score_set表，1个人，2战队
                        senateScore.setTag("英语智能课到课率");
                        iSenateScoreService.addOrUpdateSenateScoreDataNew(senateScore);
                        //} catch (Exception e) {
                        // }
                    }

                } else if (scoreSet.getTag().equals("数学刷题到课率")) {
                    // 数学刷题到课率
                    List<ArrivalRate> arrivalRateList = iTeacherFeignClient.arrivalRate(1, null, "2", null, dateNow.toString(), dateNow.toString(), null, null, "2", null, null, yearPart.toString(), quarterNum.toString(), null, null, null, null, "3", null, i.toString(), i.toString(), null, teacherId);
                    for (ArrivalRate arrivalRate : arrivalRateList) {
                        //try {
                        SenateScoreView senateScore = new SenateScoreView();
                        BigDecimal arrivalCount = new BigDecimal(arrivalRate.getArrivedCount());
                        BigDecimal studentAllCount = new BigDecimal(arrivalRate.getStudentAllCount());
                        if (studentAllCount.equals(BigDecimal.ZERO)) {
                            continue;
                        }
                        BigDecimal rade = arrivalCount.divide(studentAllCount, 4, BigDecimal.ROUND_HALF_UP);
                        rade = rade.multiply(new BigDecimal(100));
                        senateScore.setRadeNum(rade);
                        senateScore.setCount(arrivalCount);
                        senateScore.setAllCount(studentAllCount);
                        senateScore.setProjectsId(scoreSet.getSenateProjectId());//到课率
                        senateScore.setLessonNum(i);
                        senateScore.setTeacherId(arrivalRate.getTeacherId());
                        senateScore.setType(1);
                        senateScore.setSubjectsId(arrivalRate.getSubjectsId());
                        senateScore.setYearPart(yearPart);
                        senateScore.setQuarterNum(quarterNum);
                        senateScore.setScoreType(1);// 根据senate_depart_score_set表，1个人，2战队
                        senateScore.setTag("数学刷题到课率");
                        iSenateScoreService.addOrUpdateSenateScoreDataNew(senateScore);
                        //} catch (Exception e) {
                        // }
                    }
                } else if (scoreSet.getTag().equals("物理刷题到课率")) {
                    // 物理刷题到课率
                    List<ArrivalRate> arrivalRateList = iTeacherFeignClient.arrivalRate(1, null, "3", null, dateNow.toString(), dateNow.toString(), null, null, "2", null, null, yearPart.toString(), quarterNum.toString(), null, null, null, null, "3", null, i.toString(), i.toString(), null, teacherId);
                    for (ArrivalRate arrivalRate : arrivalRateList) {
                        //try {
                        SenateScoreView senateScore = new SenateScoreView();
                        BigDecimal arrivalCount = new BigDecimal(arrivalRate.getArrivedCount());
                        BigDecimal studentAllCount = new BigDecimal(arrivalRate.getStudentAllCount());
                        if (studentAllCount.equals(BigDecimal.ZERO)) {
                            continue;
                        }
                        BigDecimal rade = arrivalCount.divide(studentAllCount, 4, BigDecimal.ROUND_HALF_UP);
                        rade = rade.multiply(new BigDecimal(100));
                        senateScore.setRadeNum(rade);
                        senateScore.setCount(arrivalCount);
                        senateScore.setAllCount(studentAllCount);
                        senateScore.setProjectsId(scoreSet.getSenateProjectId());//到课率
                        senateScore.setLessonNum(i);
                        senateScore.setTeacherId(arrivalRate.getTeacherId());
                        senateScore.setType(1);
                        senateScore.setSubjectsId(arrivalRate.getSubjectsId());
                        senateScore.setYearPart(yearPart);
                        senateScore.setQuarterNum(quarterNum);
                        senateScore.setScoreType(1);// 根据senate_depart_score_set表，1个人，2战队
                        senateScore.setTag("物理刷题到课率");
                        iSenateScoreService.addOrUpdateSenateScoreDataNew(senateScore);
                        //} catch (Exception e) {
                        // }
                    }
*/
                } else if (scoreSet.getTag().equals("英语精品课准时率")) {
                    //英语精品课准时率
                    try {
                        List<ArrivalRate> arrivalRateList = iTeacherFeignClient.tardinessRateIFeign(yearPart.toString(), quarterNum.toString(), null, null, null, null, "1", i.toString(), i.toString(), null, "1", null, "5", "2", null, null, LocalDate.now().toString(), LocalDate.now().toString(), null, 1, null, teacherId, "0", "0");
                        for (ArrivalRate arrivalRate : arrivalRateList) {
                            SenateScoreView senateScore = new SenateScoreView();
                            BigDecimal arrivalCount = new BigDecimal(arrivalRate.getStudentAllCount() - arrivalRate.getTardinessRateCount() - arrivalRate.getLeaveCount());
                            BigDecimal studentAllCount = new BigDecimal(arrivalRate.getStudentAllCount());
                            if (studentAllCount.equals(BigDecimal.ZERO)) {
                                continue;
                            }
                            BigDecimal rade = arrivalCount.divide(studentAllCount, 4, BigDecimal.ROUND_HALF_UP);
                            rade = rade.multiply(new BigDecimal(100));
                            senateScore.setRadeNum(rade);
                            senateScore.setCount(arrivalCount);
                            senateScore.setAllCount(studentAllCount);
                            senateScore.setProjectsId(scoreSet.getSenateProjectId());//准时率
                            senateScore.setLessonNum(i);
                            senateScore.setTeacherId(arrivalRate.getTeacherId());
                            senateScore.setType(1);
                            senateScore.setSubjectsId(arrivalRate.getSubjectsId());
                            senateScore.setYearPart(yearPart);
                            senateScore.setQuarterNum(quarterNum);
                            senateScore.setScoreType(1);// 根据senate_depart_score_set表，1个人，2战队
                            senateScore.setTag("英语精品课准时率");
                            iSenateScoreService.addOrUpdateSenateScoreDataNew(senateScore);
                        }
                    } catch (Exception e) {
                    }
                } else if (scoreSet.getTag().equals("数学精品课准时率")) {
                    //数学精品课准时率
                    try {
                        List<ArrivalRate> arrivalRateList = iTeacherFeignClient.tardinessRateIFeign(yearPart.toString(), quarterNum.toString(), null, null, null, null, "1", i.toString(), i.toString(), null, "2", null, "5", "2", null, null, LocalDate.now().toString(), LocalDate.now().toString(), null, 1, null, teacherId, "0", "0");
                        for (ArrivalRate arrivalRate : arrivalRateList) {
                            SenateScoreView senateScore = new SenateScoreView();
                            BigDecimal arrivalCount = new BigDecimal(arrivalRate.getStudentAllCount() - arrivalRate.getTardinessRateCount() - arrivalRate.getLeaveCount());
                            BigDecimal studentAllCount = new BigDecimal(arrivalRate.getStudentAllCount());
                            if (studentAllCount.equals(BigDecimal.ZERO)) {
                                continue;
                            }
                            BigDecimal rade = arrivalCount.divide(studentAllCount, 4, BigDecimal.ROUND_HALF_UP);
                            rade = rade.multiply(new BigDecimal(100));
                            senateScore.setRadeNum(rade);
                            senateScore.setCount(arrivalCount);
                            senateScore.setAllCount(studentAllCount);
                            senateScore.setProjectsId(scoreSet.getSenateProjectId());
                            senateScore.setLessonNum(i);
                            senateScore.setTeacherId(arrivalRate.getTeacherId());
                            senateScore.setType(1);
                            senateScore.setSubjectsId(arrivalRate.getSubjectsId());
                            senateScore.setYearPart(yearPart);
                            senateScore.setQuarterNum(quarterNum);
                            senateScore.setScoreType(1);// 根据senate_depart_score_set表，1个人，2战队
                            senateScore.setTag("数学精品课准时率");
                            iSenateScoreService.addOrUpdateSenateScoreDataNew(senateScore);
                        }
                    } catch (Exception e) {
                    }
                } else if (scoreSet.getTag().equals("物理精品课准时率")) {
                    //物理精品课准时率
                    try {
                        List<ArrivalRate> arrivalRateList = iTeacherFeignClient.tardinessRateIFeign(yearPart.toString(), quarterNum.toString(), null, null, null, null, "1", i.toString(), i.toString(), null, "3", null, "5", "2", null, null, LocalDate.now().toString(), LocalDate.now().toString(), null, 1, null, teacherId, "0", "0");
                        for (ArrivalRate arrivalRate : arrivalRateList) {
                            SenateScoreView senateScore = new SenateScoreView();
                            BigDecimal arrivalCount = new BigDecimal(arrivalRate.getStudentAllCount() - arrivalRate.getTardinessRateCount() - arrivalRate.getLeaveCount());
                            BigDecimal studentAllCount = new BigDecimal(arrivalRate.getStudentAllCount());
                            if (studentAllCount.equals(BigDecimal.ZERO)) {
                                continue;
                            }
                            BigDecimal rade = arrivalCount.divide(studentAllCount, 4, BigDecimal.ROUND_HALF_UP);
                            rade = rade.multiply(new BigDecimal(100));
                            senateScore.setRadeNum(rade);
                            senateScore.setCount(arrivalCount);
                            senateScore.setAllCount(studentAllCount);
                            senateScore.setProjectsId(scoreSet.getSenateProjectId());//准时率
                            senateScore.setLessonNum(i);
                            senateScore.setTeacherId(arrivalRate.getTeacherId());
                            senateScore.setType(1);
                            senateScore.setSubjectsId(arrivalRate.getSubjectsId());
                            senateScore.setYearPart(yearPart);
                            senateScore.setQuarterNum(quarterNum);
                            senateScore.setScoreType(1);// 根据senate_depart_score_set表，1个人，2战队
                            senateScore.setTag("物理精品课准时率");
                            iSenateScoreService.addOrUpdateSenateScoreDataNew(senateScore);
                        }
                    } catch (Exception e) {
                    }
                } else if (scoreSet.getTag().equals("英语智能课通关率")) {
                    //英语智能课通关率
                    try {
                        List<PassRade> radeList = iTeacherFeignClient.getMinimumTaskProgressRateIFeign(yearPart.toString(), quarterNum.toString(), null, null, null, 1, 1, "1", null, LocalDate.now().toString(), LocalDate.now().toString(), null, null, null, "7", "2", i, i, teacherId, null);
                        for (PassRade passRade : radeList) {
                            SenateScoreView senateScore = new SenateScoreView();
                            BigDecimal arrivalCount = new BigDecimal(passRade.getAllStudentNum() - passRade.getNotStudentNum());
                            BigDecimal studentAllCount = new BigDecimal(passRade.getAllStudentNum());
                            if (studentAllCount.equals(BigDecimal.ZERO)) {
                                continue;
                            }
                            BigDecimal rade = arrivalCount.divide(studentAllCount, 4, BigDecimal.ROUND_HALF_UP);
                            rade = rade.multiply(new BigDecimal(100));
                            senateScore.setRadeNum(rade);
                            senateScore.setCount(arrivalCount);
                            senateScore.setAllCount(studentAllCount);
                            senateScore.setProjectsId(scoreSet.getSenateProjectId());
                            senateScore.setLessonNum(i);
                            senateScore.setTeacherId(passRade.getTeacherId());
                            senateScore.setType(1);
                            senateScore.setSubjectsId(scoreSet.getSubjectsId());
                            senateScore.setYearPart(yearPart);
                            senateScore.setQuarterNum(quarterNum);
                            senateScore.setScoreType(1);// 根据senate_depart_score_set表，1个人，2战队
                            senateScore.setTag("英语智能课通关率");
                            iSenateScoreService.addOrUpdateSenateScoreDataNew(senateScore);
                        }
                    } catch (Exception e) {
                    }
                } else if (scoreSet.getTag().equals("英语智能课正确率")) {
                    //英语智能课正确率
                    try {
                        List<PassRade> radeList = iTeacherFeignClient.getMinimumTaskProgressRateIFeign(yearPart.toString(), quarterNum.toString(), null, null, null, 1, 1, "1", null, LocalDate.now().toString(), LocalDate.now().toString(), null, null, null, "7", "2", i, i, teacherId, null);
                        for (PassRade passRade : radeList) {
                            SenateScoreView senateScore = new SenateScoreView();
                            BigDecimal arrivalCount = new BigDecimal(passRade.getFirstRightCount());
                            BigDecimal studentAllCount = new BigDecimal(passRade.getFirstWordCount());
                            if (studentAllCount.equals(BigDecimal.ZERO)) {
                                continue;
                            }
                            BigDecimal rade = arrivalCount.divide(studentAllCount, 4, BigDecimal.ROUND_HALF_UP);
                            rade = rade.multiply(new BigDecimal(100));
                            senateScore.setRadeNum(rade);
                            senateScore.setCount(arrivalCount);
                            senateScore.setAllCount(studentAllCount);
                            senateScore.setProjectsId(scoreSet.getSenateProjectId());
                            senateScore.setLessonNum(i);
                            senateScore.setTeacherId(passRade.getTeacherId());
                            senateScore.setType(1);
                            senateScore.setSubjectsId(scoreSet.getSubjectsId());
                            senateScore.setYearPart(yearPart);
                            senateScore.setQuarterNum(quarterNum);
                            senateScore.setScoreType(1);// 根据senate_depart_score_set表，1个人，2战队
                            senateScore.setTag("英语智能课正确率");
                            iSenateScoreService.addOrUpdateSenateScoreDataNew(senateScore);
                        }
                    } catch (Exception e) {
                    }
                } else if (scoreSet.getTag().equals("数学刷题通关率")) {
                    //数学刷题通关率
                    try {
                        List<MathChaPlan> mathChaPlanList = iTeacherFeignClient.getPassRadeListIFeign(null, yearPart.toString(), quarterNum.toString(), "1", i.toString(), i.toString(), null, null, null, "1", LocalDate.now().toString(), LocalDate.now().toString(), LocalDate.now().toString(), "2", "", "", null, null, "1", teacherId, null, null, null, null, null, null, "1", null, null, null, null);

                        for (MathChaPlan mathChaPlan : mathChaPlanList) {
                            SenateScoreView senateScore = new SenateScoreView();
                            BigDecimal arrivalCount = new BigDecimal(mathChaPlan.getYetFinishCount2());
                            BigDecimal studentAllCount = new BigDecimal(mathChaPlan.getShowPassNum());
                            if (studentAllCount.equals(BigDecimal.ZERO)) {
                                continue;
                            }
                            BigDecimal rade = arrivalCount.divide(studentAllCount, 4, BigDecimal.ROUND_HALF_UP);
                            rade = rade.multiply(new BigDecimal(100));
                            senateScore.setRadeNum(rade);
                            senateScore.setCount(arrivalCount);
                            senateScore.setAllCount(studentAllCount);
                            senateScore.setProjectsId(scoreSet.getSenateProjectId());
                            senateScore.setLessonNum(i);
                            senateScore.setTeacherId(mathChaPlan.getTeacherId());
                            senateScore.setType(1);
                            senateScore.setSubjectsId(scoreSet.getSubjectsId());
                            senateScore.setYearPart(yearPart);
                            senateScore.setQuarterNum(quarterNum);
                            senateScore.setScoreType(1);// 根据senate_depart_score_set表，1个人，2战队
                            senateScore.setTag("数学刷题通关率");
                            iSenateScoreService.addOrUpdateSenateScoreDataNew(senateScore);
                        }
                    } catch (Exception e) {
                    }
                } else if (scoreSet.getTag().equals("数学刷题正确率")) {
                    //数学刷题正确率
                    try {
                        List<MathChaPlan> mathChaPlanList = iTeacherFeignClient.getPassRadeListIFeign(null, yearPart.toString(), quarterNum.toString(), "1", i.toString(), i.toString(), null, null, null, "1", LocalDate.now().toString(), LocalDate.now().toString(), LocalDate.now().toString(), "2", "", "", null, null, "2", teacherId, null, null, null, null, null, null, "2", null, null, null, null);

                        for (MathChaPlan mathChaPlan : mathChaPlanList) {
                            if (mathChaPlan.getRightNumAll() == null || mathChaPlan.getLowestShutnumAll() == null) {
                                continue;
                            }
                            SenateScoreView senateScore = new SenateScoreView();
                            BigDecimal arrivalCount = new BigDecimal(mathChaPlan.getRightNumAll());
                            BigDecimal studentAllCount = new BigDecimal(mathChaPlan.getLowestShutnumAll());
                            if (studentAllCount.equals(BigDecimal.ZERO)) {
                                continue;
                            }
                            BigDecimal rade = arrivalCount.divide(studentAllCount, 4, BigDecimal.ROUND_HALF_UP);
                            rade = rade.multiply(new BigDecimal(100));
                            senateScore.setRadeNum(rade);
                            senateScore.setCount(arrivalCount);
                            senateScore.setAllCount(studentAllCount);
                            senateScore.setProjectsId(scoreSet.getSenateProjectId());
                            senateScore.setLessonNum(i);
                            senateScore.setTeacherId(mathChaPlan.getTeacherId());
                            senateScore.setType(1);
                            senateScore.setSubjectsId(scoreSet.getSubjectsId());
                            senateScore.setYearPart(yearPart);
                            senateScore.setQuarterNum(quarterNum);
                            senateScore.setScoreType(1);// 根据senate_depart_score_set表，1个人，2战队
                            senateScore.setTag("数学刷题正确率");
                            iSenateScoreService.addOrUpdateSenateScoreDataNew(senateScore);
                        }
                    } catch (Exception e) {
                    }
                } else if (scoreSet.getTag().equals("物理刷题通关率")) {
                    //物理刷题通关率
                    try {
                        List<MathChaPlan> mathChaPlanList = iTeacherFeignClient.getPassRadeListIFeign(null, yearPart.toString(), quarterNum.toString(), "1", i.toString(), i.toString(), null, null, null, "1", LocalDate.now().toString(), LocalDate.now().toString(), LocalDate.now().toString(), "3", "", "", null, null, "1", teacherId, null, null, null, null, null, null, "1", null, null, null, null);

                        for (MathChaPlan mathChaPlan : mathChaPlanList) {
                            SenateScoreView senateScore = new SenateScoreView();
                            BigDecimal arrivalCount = new BigDecimal(mathChaPlan.getYetFinishCount2());
                            BigDecimal studentAllCount = new BigDecimal(mathChaPlan.getShowPassNum());
                            if (studentAllCount.equals(BigDecimal.ZERO)) {
                                continue;
                            }
                            BigDecimal rade = arrivalCount.divide(studentAllCount, 4, BigDecimal.ROUND_HALF_UP);
                            rade = rade.multiply(new BigDecimal(100));
                            senateScore.setRadeNum(rade);
                            senateScore.setCount(arrivalCount);
                            senateScore.setAllCount(studentAllCount);
                            senateScore.setProjectsId(scoreSet.getSenateProjectId());
                            senateScore.setLessonNum(i);
                            senateScore.setTeacherId(mathChaPlan.getTeacherId());
                            senateScore.setType(1);
                            senateScore.setSubjectsId(scoreSet.getSubjectsId());
                            senateScore.setYearPart(yearPart);
                            senateScore.setQuarterNum(quarterNum);
                            senateScore.setScoreType(1);// 根据senate_depart_score_set表，1个人，2战队
                            senateScore.setTag("物理刷题通关率");
                            iSenateScoreService.addOrUpdateSenateScoreDataNew(senateScore);
                        }
                    } catch (Exception e) {
                    }
                } else if (scoreSet.getTag().equals("物理刷题正确率")) {
                    //物理刷题正确率
                    try {
                        List<MathChaPlan> mathChaPlanList = iTeacherFeignClient.getPhysicsPassRadeListIFeign(null, yearPart.toString(), quarterNum.toString(), "1", i.toString(), i.toString(), null, null, null, "1", LocalDate.now().toString(), LocalDate.now().toString(), LocalDate.now().toString(), "3", "", "", null, null, "2", null, null, null, null, null, null, null, "2", null, null, null, null);

                        for (MathChaPlan mathChaPlan : mathChaPlanList) {
                            if (mathChaPlan.getRightNumAll() == null || mathChaPlan.getLowestShutnumAll() == null) {
                                continue;
                            }
                            SenateScoreView senateScore = new SenateScoreView();
                            BigDecimal arrivalCount = new BigDecimal(mathChaPlan.getRightNumAll());
                            BigDecimal studentAllCount = new BigDecimal(mathChaPlan.getLowestShutnumAll());
                            if (studentAllCount.equals(BigDecimal.ZERO)) {
                                continue;
                            }
                            BigDecimal rade = arrivalCount.divide(studentAllCount, 4, BigDecimal.ROUND_HALF_UP);
                            rade = rade.multiply(new BigDecimal(100));
                            senateScore.setRadeNum(rade);
                            senateScore.setCount(arrivalCount);
                            senateScore.setAllCount(studentAllCount);
                            senateScore.setProjectsId(scoreSet.getSenateProjectId());
                            senateScore.setLessonNum(i);
                            senateScore.setTeacherId(mathChaPlan.getTeacherId());
                            senateScore.setType(1);
                            senateScore.setSubjectsId(scoreSet.getSubjectsId());
                            senateScore.setYearPart(yearPart);
                            senateScore.setQuarterNum(quarterNum);
                            senateScore.setScoreType(1);// 根据senate_depart_score_set表，1个人，2战队
                            senateScore.setTag("物理刷题正确率");
                            iSenateScoreService.addOrUpdateSenateScoreDataNew(senateScore);
                        }
                    } catch (Exception e) {
                    }
                }
            }
        }

        for (int yearClassId = 0; yearClassId <= 12; yearClassId++) {
            for (Integer i = startLessonNum; i <= endLessonNum; i++) {
                for (SenateDepartScoreSet scoreSet : senateDepartScoreSets) {
                    //英语精品课到课率
                    if (scoreSet.getTag().equals("英语精品课到课率")) {
                        try {
                            List<ArrivalRate> arrivalRateList = iTeacherFeignClient.arrivalRate(1, null, "1", null, dateNow.toString(), dateNow.toString(), null, null, "2", null, null, yearPart.toString(), quarterNum.toString(), null, null, null, String.valueOf(yearClassId), "1", null, i.toString(), i.toString(), null, teacherId, "0", "0");
                            for (ArrivalRate arrivalRate : arrivalRateList) {
                                SenateScoreView senateScore = new SenateScoreView();
                                BigDecimal arrivalCount = new BigDecimal(arrivalRate.getArrivedCount());
                                BigDecimal studentAllCount = new BigDecimal(arrivalRate.getStudentAllCount());
                                if (studentAllCount.equals(BigDecimal.ZERO)) {
                                    continue;
                                }
                                BigDecimal rade = arrivalCount.divide(studentAllCount, 4, BigDecimal.ROUND_HALF_UP);
                                rade = rade.multiply(new BigDecimal(100));
                                senateScore.setRadeNum(rade);
                                senateScore.setCount(arrivalCount);
                                senateScore.setAllCount(studentAllCount);
                                senateScore.setProjectsId(scoreSet.getSenateProjectId());//到课率
                                senateScore.setLessonNum(i);
                                senateScore.setTeacherId(arrivalRate.getTeacherId());
                                senateScore.setType(1);
                                senateScore.setSubjectsId(arrivalRate.getSubjectsId());
                                senateScore.setYearPart(yearPart);
                                senateScore.setQuarterNum(quarterNum);
                                senateScore.setScoreType(1);// 根据senate_depart_score_set表，1个人，2战队
                                senateScore.setType(1);
                                senateScore.setYearClassId(yearClassId);
                                senateScore.setTag("英语精品课到课率");
                                iSenateScoreService.addOrUpdateSenateScoreDataNew(senateScore);
                            }
                        } catch (Exception e) {
                        }
                    } else if (scoreSet.getTag().equals("数学精品课到课率")) {
                        // 数学精品课到课率
                        try {
                            List<ArrivalRate> arrivalRateList = iTeacherFeignClient.arrivalRate(1, null, "2", null, dateNow.toString(), dateNow.toString(), null, null, "2", null, null, yearPart.toString(), quarterNum.toString(), null, null, null, String.valueOf(yearClassId), "1", null, i.toString(), i.toString(), null, teacherId, "0", "0");
                            for (ArrivalRate arrivalRate : arrivalRateList) {

                                SenateScoreView senateScore = new SenateScoreView();
                                BigDecimal arrivalCount = new BigDecimal(arrivalRate.getArrivedCount());
                                BigDecimal studentAllCount = new BigDecimal(arrivalRate.getStudentAllCount());
                                if (studentAllCount.equals(BigDecimal.ZERO)) {
                                    continue;
                                }
                                BigDecimal rade = arrivalCount.divide(studentAllCount, 4, BigDecimal.ROUND_HALF_UP);
                                rade = rade.multiply(new BigDecimal(100));
                                senateScore.setRadeNum(rade);
                                senateScore.setCount(arrivalCount);
                                senateScore.setAllCount(studentAllCount);
                                senateScore.setProjectsId(scoreSet.getSenateProjectId());//到课率
                                senateScore.setLessonNum(i);
                                senateScore.setTeacherId(arrivalRate.getTeacherId());
                                senateScore.setType(1);
                                senateScore.setSubjectsId(arrivalRate.getSubjectsId());
                                senateScore.setYearPart(yearPart);
                                senateScore.setQuarterNum(quarterNum);
                                senateScore.setScoreType(1);// 根据senate_depart_score_set表，1个人，2战队
                                senateScore.setType(1);
                                senateScore.setYearClassId(yearClassId);
                                senateScore.setTag("数学精品课到课率");
                                iSenateScoreService.addOrUpdateSenateScoreDataNew(senateScore);
                            }
                        } catch (Exception e) {
                        }
                    } else if (scoreSet.getTag().equals("物理精品课到课率")) {
                        // 物理精品课到课率
                        try {
                            List<ArrivalRate> arrivalRateList = iTeacherFeignClient.arrivalRate(1, null, "3", null, dateNow.toString(), dateNow.toString(), null, null, "2", null, null, yearPart.toString(), quarterNum.toString(), null, null, null, String.valueOf(yearClassId), "1", null, i.toString(), i.toString(), null, teacherId, "0", "0");
                            for (ArrivalRate arrivalRate : arrivalRateList) {
                                SenateScoreView senateScore = new SenateScoreView();
                                BigDecimal arrivalCount = new BigDecimal(arrivalRate.getArrivedCount());
                                BigDecimal studentAllCount = new BigDecimal(arrivalRate.getStudentAllCount());
                                if (studentAllCount.equals(BigDecimal.ZERO)) {
                                    continue;
                                }
                                BigDecimal rade = arrivalCount.divide(studentAllCount, 4, BigDecimal.ROUND_HALF_UP);
                                rade = rade.multiply(new BigDecimal(100));
                                senateScore.setRadeNum(rade);
                                senateScore.setCount(arrivalCount);
                                senateScore.setAllCount(studentAllCount);
                                senateScore.setProjectsId(scoreSet.getSenateProjectId());//到课率
                                senateScore.setLessonNum(i);
                                senateScore.setTeacherId(arrivalRate.getTeacherId());
                                senateScore.setType(1);
                                senateScore.setSubjectsId(arrivalRate.getSubjectsId());
                                senateScore.setYearPart(yearPart);
                                senateScore.setQuarterNum(quarterNum);
                                senateScore.setScoreType(1);// 根据senate_depart_score_set表，1个人，2战队
                                senateScore.setType(1);
                                senateScore.setYearClassId(yearClassId);
                                senateScore.setTag("物理精品课到课率");
                                iSenateScoreService.addOrUpdateSenateScoreDataNew(senateScore);
                            }
                        } catch (Exception e) {
                        }
                    /*} else if (scoreSet.getTag().equals("英语智能课到课率")) {
                        // 英语智能课到课率
                        List<ArrivalRate> arrivalRateList = iTeacherFeignClient.arrivalRate(1, null, "1", null, dateNow.toString(), dateNow.toString(), null, null, "2", null, null, yearPart.toString(), quarterNum.toString(), null, null, null, String.valueOf(yearClassId), "2", null, i.toString(), i.toString(), null, teacherId,"0","0");
                        for (ArrivalRate arrivalRate : arrivalRateList) {
                            //try {
                            SenateScoreView senateScore = new SenateScoreView();
                            BigDecimal arrivalCount = new BigDecimal(arrivalRate.getArrivedCount());
                            BigDecimal studentAllCount = new BigDecimal(arrivalRate.getStudentAllCount());
                            if (studentAllCount.equals(BigDecimal.ZERO)) {
                                continue;
                            }
                            BigDecimal rade = arrivalCount.divide(studentAllCount, 4, BigDecimal.ROUND_HALF_UP);
                            rade = rade.multiply(new BigDecimal(100));
                            senateScore.setRadeNum(rade);
                            senateScore.setCount(arrivalCount);
                            senateScore.setAllCount(studentAllCount);
                            senateScore.setProjectsId(scoreSet.getSenateProjectId());
                            senateScore.setLessonNum(i);
                            senateScore.setTeacherId(arrivalRate.getTeacherId());
                            senateScore.setType(1);
                            senateScore.setSubjectsId(arrivalRate.getSubjectsId());
                            senateScore.setYearPart(yearPart);
                            senateScore.setQuarterNum(quarterNum);
                            senateScore.setScoreType(1);// 根据senate_depart_score_set表，1个人，2战队
                            senateScore.setType(1);
                            senateScore.setYearClassId(yearClassId);
                            senateScore.setTag("英语智能课到课率");
                            iSenateScoreService.addOrUpdateSenateScoreDataNew(senateScore);
                            //} catch (Exception e) {
                            // }
                        }

                    } else if (scoreSet.getTag().equals("数学刷题到课率")) {
                        // 数学刷题到课率
                        List<ArrivalRate> arrivalRateList = iTeacherFeignClient.arrivalRate(1, null, "2", null, dateNow.toString(), dateNow.toString(), null, null, "2", null, null, yearPart.toString(), quarterNum.toString(), null, null, null, String.valueOf(yearClassId), "3", null, i.toString(), i.toString(), null, teacherId,"0","0");
                        for (ArrivalRate arrivalRate : arrivalRateList) {
                            //try {
                            SenateScoreView senateScore = new SenateScoreView();
                            BigDecimal arrivalCount = new BigDecimal(arrivalRate.getArrivedCount());
                            BigDecimal studentAllCount = new BigDecimal(arrivalRate.getStudentAllCount());
                            if (studentAllCount.equals(BigDecimal.ZERO)) {
                                continue;
                            }
                            BigDecimal rade = arrivalCount.divide(studentAllCount, 4, BigDecimal.ROUND_HALF_UP);
                            rade = rade.multiply(new BigDecimal(100));
                            senateScore.setRadeNum(rade);
                            senateScore.setCount(arrivalCount);
                            senateScore.setAllCount(studentAllCount);
                            senateScore.setProjectsId(scoreSet.getSenateProjectId());//到课率
                            senateScore.setLessonNum(i);
                            senateScore.setTeacherId(arrivalRate.getTeacherId());
                            senateScore.setType(1);
                            senateScore.setSubjectsId(arrivalRate.getSubjectsId());
                            senateScore.setYearPart(yearPart);
                            senateScore.setQuarterNum(quarterNum);
                            senateScore.setScoreType(1);// 根据senate_depart_score_set表，1个人，2战队
                            senateScore.setType(1);
                            senateScore.setYearClassId(yearClassId);
                            senateScore.setTag("数学刷题到课率");
                            iSenateScoreService.addOrUpdateSenateScoreDataNew(senateScore);
                            //} catch (Exception e) {
                            // }
                        }
                    } else if (scoreSet.getTag().equals("物理刷题到课率")) {
                        // 物理刷题到课率
                        List<ArrivalRate> arrivalRateList = iTeacherFeignClient.arrivalRate(1, null, "3", null, dateNow.toString(), dateNow.toString(), null, null, "2", null, null, yearPart.toString(), quarterNum.toString(), null, null, null, String.valueOf(yearClassId), "3", null, i.toString(), i.toString(), null, teacherId,"0","0");
                        for (ArrivalRate arrivalRate : arrivalRateList) {
                            //try {
                            SenateScoreView senateScore = new SenateScoreView();
                            BigDecimal arrivalCount = new BigDecimal(arrivalRate.getArrivedCount());
                            BigDecimal studentAllCount = new BigDecimal(arrivalRate.getStudentAllCount());
                            if (studentAllCount.equals(BigDecimal.ZERO)) {
                                continue;
                            }
                            BigDecimal rade = arrivalCount.divide(studentAllCount, 4, BigDecimal.ROUND_HALF_UP);
                            rade = rade.multiply(new BigDecimal(100));
                            senateScore.setRadeNum(rade);
                            senateScore.setCount(arrivalCount);
                            senateScore.setAllCount(studentAllCount);
                            senateScore.setProjectsId(scoreSet.getSenateProjectId());//到课率
                            senateScore.setLessonNum(i);
                            senateScore.setTeacherId(arrivalRate.getTeacherId());
                            senateScore.setType(1);
                            senateScore.setSubjectsId(arrivalRate.getSubjectsId());
                            senateScore.setYearPart(yearPart);
                            senateScore.setQuarterNum(quarterNum);
                            senateScore.setScoreType(1);// 根据senate_depart_score_set表，1个人，2战队
                            senateScore.setType(1);
                            senateScore.setYearClassId(yearClassId);
                            senateScore.setTag("物理刷题到课率");
                            iSenateScoreService.addOrUpdateSenateScoreDataNew(senateScore);
                            //} catch (Exception e) {
                            // }
                        }
*/
                    } else if (scoreSet.getTag().equals("英语精品课准时率")) {
                        //英语精品课准时率
                        try {
                            List<ArrivalRate> arrivalRateList = iTeacherFeignClient.tardinessRateIFeign(yearPart.toString(), quarterNum.toString(), null, null, null, String.valueOf(yearClassId), "1", i.toString(), i.toString(), null, "1", null, "5", "2", null, null, LocalDate.now().toString(), LocalDate.now().toString(), null, 1, null, teacherId, "0", "0");
                            for (ArrivalRate arrivalRate : arrivalRateList) {
                                SenateScoreView senateScore = new SenateScoreView();
                                BigDecimal arrivalCount = new BigDecimal(arrivalRate.getStudentAllCount() - arrivalRate.getTardinessRateCount() - arrivalRate.getLeaveCount());
                                BigDecimal studentAllCount = new BigDecimal(arrivalRate.getStudentAllCount());
                                if (studentAllCount.equals(BigDecimal.ZERO)) {
                                    continue;
                                }
                                BigDecimal rade = arrivalCount.divide(studentAllCount, 4, BigDecimal.ROUND_HALF_UP);
                                rade = rade.multiply(new BigDecimal(100));
                                senateScore.setRadeNum(rade);
                                senateScore.setCount(arrivalCount);
                                senateScore.setAllCount(studentAllCount);
                                senateScore.setProjectsId(scoreSet.getSenateProjectId());//准时率
                                senateScore.setLessonNum(i);
                                senateScore.setTeacherId(arrivalRate.getTeacherId());
                                senateScore.setType(1);
                                senateScore.setSubjectsId(arrivalRate.getSubjectsId());
                                senateScore.setYearPart(yearPart);
                                senateScore.setQuarterNum(quarterNum);
                                senateScore.setScoreType(1);// 根据senate_depart_score_set表，1个人，2战队
                                senateScore.setType(1);
                                senateScore.setYearClassId(yearClassId);
                                senateScore.setTag("英语精品课准时率");
                                iSenateScoreService.addOrUpdateSenateScoreDataNew(senateScore);
                            }
                        } catch (Exception e) {
                        }
                    } else if (scoreSet.getTag().equals("数学精品课准时率")) {
                        //数学精品课准时率
                        try {
                            List<ArrivalRate> arrivalRateList = iTeacherFeignClient.tardinessRateIFeign(yearPart.toString(), quarterNum.toString(), null, null, null, String.valueOf(yearClassId), "1", i.toString(), i.toString(), null, "2", null, "5", "2", null, null, LocalDate.now().toString(), LocalDate.now().toString(), null, 1, null, teacherId, "0", "0");
                            for (ArrivalRate arrivalRate : arrivalRateList) {

                                SenateScoreView senateScore = new SenateScoreView();
                                BigDecimal arrivalCount = new BigDecimal(arrivalRate.getStudentAllCount() - arrivalRate.getTardinessRateCount() - arrivalRate.getLeaveCount());
                                BigDecimal studentAllCount = new BigDecimal(arrivalRate.getStudentAllCount());
                                if (studentAllCount.equals(BigDecimal.ZERO)) {
                                    continue;
                                }
                                BigDecimal rade = arrivalCount.divide(studentAllCount, 4, BigDecimal.ROUND_HALF_UP);
                                rade = rade.multiply(new BigDecimal(100));
                                senateScore.setRadeNum(rade);
                                senateScore.setCount(arrivalCount);
                                senateScore.setAllCount(studentAllCount);
                                senateScore.setProjectsId(scoreSet.getSenateProjectId());
                                senateScore.setLessonNum(i);
                                senateScore.setTeacherId(arrivalRate.getTeacherId());
                                senateScore.setType(1);
                                senateScore.setSubjectsId(arrivalRate.getSubjectsId());
                                senateScore.setYearPart(yearPart);
                                senateScore.setQuarterNum(quarterNum);
                                senateScore.setScoreType(1);// 根据senate_depart_score_set表，1个人，2战队
                                senateScore.setType(1);
                                senateScore.setYearClassId(yearClassId);
                                senateScore.setTag("数学精品课准时率");
                                iSenateScoreService.addOrUpdateSenateScoreDataNew(senateScore);
                            }
                        } catch (Exception e) {
                        }
                    } else if (scoreSet.getTag().equals("物理精品课准时率")) {
                        //物理精品课准时率
                        try {
                            List<ArrivalRate> arrivalRateList = iTeacherFeignClient.tardinessRateIFeign(yearPart.toString(), quarterNum.toString(), null, null, null, String.valueOf(yearClassId), "1", i.toString(), i.toString(), null, "3", null, "5", "2", null, null, LocalDate.now().toString(), LocalDate.now().toString(), null, 1, null, teacherId, "0", "0");
                            for (ArrivalRate arrivalRate : arrivalRateList) {
                                SenateScoreView senateScore = new SenateScoreView();
                                BigDecimal arrivalCount = new BigDecimal(arrivalRate.getStudentAllCount() - arrivalRate.getTardinessRateCount() - arrivalRate.getLeaveCount());
                                BigDecimal studentAllCount = new BigDecimal(arrivalRate.getStudentAllCount());
                                if (studentAllCount.equals(BigDecimal.ZERO)) {
                                    continue;
                                }
                                BigDecimal rade = arrivalCount.divide(studentAllCount, 4, BigDecimal.ROUND_HALF_UP);
                                rade = rade.multiply(new BigDecimal(100));
                                senateScore.setRadeNum(rade);
                                senateScore.setCount(arrivalCount);
                                senateScore.setAllCount(studentAllCount);
                                senateScore.setProjectsId(scoreSet.getSenateProjectId());//准时率
                                senateScore.setLessonNum(i);
                                senateScore.setTeacherId(arrivalRate.getTeacherId());
                                senateScore.setType(1);
                                senateScore.setSubjectsId(arrivalRate.getSubjectsId());
                                senateScore.setYearPart(yearPart);
                                senateScore.setQuarterNum(quarterNum);
                                senateScore.setScoreType(1);// 根据senate_depart_score_set表，1个人，2战队
                                senateScore.setType(1);
                                senateScore.setYearClassId(yearClassId);
                                senateScore.setTag("物理精品课准时率");
                                iSenateScoreService.addOrUpdateSenateScoreDataNew(senateScore);
                            }
                        } catch (Exception e) {
                        }
                    } else if (scoreSet.getTag().equals("英语智能课通关率")) {
                        //英语智能课通关率
                        try {
                            List<PassRade> radeList = iTeacherFeignClient.getMinimumTaskProgressRateIFeign(yearPart.toString(), quarterNum.toString(), String.valueOf(yearClassId), null, null, 1, 1, "1", null, LocalDate.now().toString(), LocalDate.now().toString(), null, null, null, "7", "2", i, i, teacherId, null);
                            for (PassRade passRade : radeList) {
                                SenateScoreView senateScore = new SenateScoreView();
                                BigDecimal arrivalCount = new BigDecimal(passRade.getAllStudentNum() - passRade.getNotStudentNum());
                                BigDecimal studentAllCount = new BigDecimal(passRade.getAllStudentNum());
                                if (studentAllCount.equals(BigDecimal.ZERO)) {
                                    continue;
                                }
                                BigDecimal rade = arrivalCount.divide(studentAllCount, 4, BigDecimal.ROUND_HALF_UP);
                                rade = rade.multiply(new BigDecimal(100));
                                senateScore.setRadeNum(rade);
                                senateScore.setCount(arrivalCount);
                                senateScore.setAllCount(studentAllCount);
                                senateScore.setProjectsId(scoreSet.getSenateProjectId());
                                senateScore.setLessonNum(i);
                                senateScore.setTeacherId(passRade.getTeacherId());
                                senateScore.setType(1);
                                senateScore.setSubjectsId(scoreSet.getSubjectsId());
                                senateScore.setYearPart(yearPart);
                                senateScore.setQuarterNum(quarterNum);
                                senateScore.setScoreType(1);// 根据senate_depart_score_set表，1个人，2战队
                                senateScore.setType(1);
                                senateScore.setYearClassId(yearClassId);
                                senateScore.setTag("英语智能课通关率");
                                iSenateScoreService.addOrUpdateSenateScoreDataNew(senateScore);
                            }
                        } catch (Exception e) {
                        }
                    } else if (scoreSet.getTag().equals("英语智能课正确率")) {
                        //英语智能课正确率
                        try {
                            List<PassRade> radeList = iTeacherFeignClient.getMinimumTaskProgressRateIFeign(yearPart.toString(), quarterNum.toString(), String.valueOf(yearClassId), null, null, 1, 1, "1", null, LocalDate.now().toString(), LocalDate.now().toString(), null, null, null, "7", "2", i, i, teacherId, null);
                            for (PassRade passRade : radeList) {
                                SenateScoreView senateScore = new SenateScoreView();
                                BigDecimal arrivalCount = new BigDecimal(passRade.getFirstRightCount());
                                BigDecimal studentAllCount = new BigDecimal(passRade.getFirstWordCount());
                                if (studentAllCount.equals(BigDecimal.ZERO)) {
                                    continue;
                                }
                                BigDecimal rade = arrivalCount.divide(studentAllCount, 4, BigDecimal.ROUND_HALF_UP);
                                rade = rade.multiply(new BigDecimal(100));
                                senateScore.setRadeNum(rade);
                                senateScore.setCount(arrivalCount);
                                senateScore.setAllCount(studentAllCount);
                                senateScore.setProjectsId(scoreSet.getSenateProjectId());
                                senateScore.setLessonNum(i);
                                senateScore.setTeacherId(passRade.getTeacherId());
                                senateScore.setType(1);
                                senateScore.setSubjectsId(scoreSet.getSubjectsId());
                                senateScore.setYearPart(yearPart);
                                senateScore.setQuarterNum(quarterNum);
                                senateScore.setScoreType(1);// 根据senate_depart_score_set表，1个人，2战队
                                senateScore.setType(1);
                                senateScore.setYearClassId(yearClassId);
                                senateScore.setTag("英语智能课正确率");
                                iSenateScoreService.addOrUpdateSenateScoreDataNew(senateScore);
                            }
                        } catch (Exception e) {
                        }
                    } else if (scoreSet.getTag().equals("数学刷题通关率")) {
                        //数学刷题通关率
                        try {
                            List<MathChaPlan> mathChaPlanList = iTeacherFeignClient.getPassRadeListIFeign(null, yearPart.toString(), quarterNum.toString(), "1", i.toString(), i.toString(), String.valueOf(yearClassId), null, null, "1", LocalDate.now().toString(), LocalDate.now().toString(), LocalDate.now().toString(), "2", "", "", null, null, "1", teacherId, null, null, null, null, null, null, "1", null, null, null, null);

                            for (MathChaPlan mathChaPlan : mathChaPlanList) {
                                SenateScoreView senateScore = new SenateScoreView();
                                BigDecimal arrivalCount = new BigDecimal(mathChaPlan.getYetFinishCount2());
                                BigDecimal studentAllCount = new BigDecimal(mathChaPlan.getShowPassNum());
                                if (studentAllCount.equals(BigDecimal.ZERO)) {
                                    continue;
                                }
                                BigDecimal rade = arrivalCount.divide(studentAllCount, 4, BigDecimal.ROUND_HALF_UP);
                                rade = rade.multiply(new BigDecimal(100));
                                senateScore.setRadeNum(rade);
                                senateScore.setCount(arrivalCount);
                                senateScore.setAllCount(studentAllCount);
                                senateScore.setProjectsId(scoreSet.getSenateProjectId());
                                senateScore.setLessonNum(i);
                                senateScore.setTeacherId(mathChaPlan.getTeacherId());
                                senateScore.setType(1);
                                senateScore.setSubjectsId(scoreSet.getSubjectsId());
                                senateScore.setYearPart(yearPart);
                                senateScore.setQuarterNum(quarterNum);
                                senateScore.setScoreType(1);// 根据senate_depart_score_set表，1个人，2战队
                                senateScore.setType(1);
                                senateScore.setYearClassId(yearClassId);
                                senateScore.setTag("数学刷题通关率");
                                iSenateScoreService.addOrUpdateSenateScoreDataNew(senateScore);
                            }
                        } catch (Exception e) {
                        }
                    } else if (scoreSet.getTag().equals("数学刷题正确率")) {
                        //数学刷题正确率
                        try {
                            List<MathChaPlan> mathChaPlanList = iTeacherFeignClient.getPassRadeListIFeign(null, yearPart.toString(), quarterNum.toString(), "1", i.toString(), i.toString(), String.valueOf(yearClassId), null, null, "1", LocalDate.now().toString(), LocalDate.now().toString(), LocalDate.now().toString(), "2", "", "", null, null, "2", teacherId, null, null, null, null, null, null, "2", null, null, null, null);

                            for (MathChaPlan mathChaPlan : mathChaPlanList) {
                                if (mathChaPlan.getRightNumAll() == null || mathChaPlan.getLowestShutnumAll() == null) {
                                    continue;
                                }
                                SenateScoreView senateScore = new SenateScoreView();
                                BigDecimal arrivalCount = new BigDecimal(mathChaPlan.getRightNumAll());
                                BigDecimal studentAllCount = new BigDecimal(mathChaPlan.getLowestShutnumAll());
                                if (studentAllCount.equals(BigDecimal.ZERO)) {
                                    continue;
                                }
                                BigDecimal rade = arrivalCount.divide(studentAllCount, 4, BigDecimal.ROUND_HALF_UP);
                                rade = rade.multiply(new BigDecimal(100));
                                senateScore.setRadeNum(rade);
                                senateScore.setCount(arrivalCount);
                                senateScore.setAllCount(studentAllCount);
                                senateScore.setProjectsId(scoreSet.getSenateProjectId());
                                senateScore.setLessonNum(i);
                                senateScore.setTeacherId(mathChaPlan.getTeacherId());
                                senateScore.setType(1);
                                senateScore.setSubjectsId(scoreSet.getSubjectsId());
                                senateScore.setYearPart(yearPart);
                                senateScore.setQuarterNum(quarterNum);
                                senateScore.setScoreType(1);// 根据senate_depart_score_set表，1个人，2战队
                                senateScore.setType(1);
                                senateScore.setYearClassId(yearClassId);
                                senateScore.setTag("数学刷题正确率");
                                iSenateScoreService.addOrUpdateSenateScoreDataNew(senateScore);
                            }
                        } catch (Exception e) {
                        }
                    } else if (scoreSet.getTag().equals("物理刷题通关率")) {
                        //物理刷题通关率
                        try {
                            List<MathChaPlan> mathChaPlanList = iTeacherFeignClient.getPassRadeListIFeign(null, yearPart.toString(), quarterNum.toString(), "1", i.toString(), i.toString(), String.valueOf(yearClassId), null, null, "1", LocalDate.now().toString(), LocalDate.now().toString(), LocalDate.now().toString(), "3", "", "", null, null, "1", teacherId, null, null, null, null, null, null, "1", null, null, null, null);

                            for (MathChaPlan mathChaPlan : mathChaPlanList) {
                                SenateScoreView senateScore = new SenateScoreView();
                                BigDecimal arrivalCount = new BigDecimal(mathChaPlan.getYetFinishCount2());
                                BigDecimal studentAllCount = new BigDecimal(mathChaPlan.getShowPassNum());
                                if (studentAllCount.equals(BigDecimal.ZERO)) {
                                    continue;
                                }
                                BigDecimal rade = arrivalCount.divide(studentAllCount, 4, BigDecimal.ROUND_HALF_UP);
                                rade = rade.multiply(new BigDecimal(100));
                                senateScore.setRadeNum(rade);
                                senateScore.setCount(arrivalCount);
                                senateScore.setAllCount(studentAllCount);
                                senateScore.setProjectsId(scoreSet.getSenateProjectId());
                                senateScore.setLessonNum(i);
                                senateScore.setTeacherId(mathChaPlan.getTeacherId());
                                senateScore.setType(1);
                                senateScore.setSubjectsId(scoreSet.getSubjectsId());
                                senateScore.setYearPart(yearPart);
                                senateScore.setQuarterNum(quarterNum);
                                senateScore.setScoreType(1);// 根据senate_depart_score_set表，1个人，2战队
                                senateScore.setType(1);
                                senateScore.setYearClassId(yearClassId);
                                senateScore.setTag("物理刷题通关率");
                                iSenateScoreService.addOrUpdateSenateScoreDataNew(senateScore);
                            }
                        } catch (Exception e) {
                        }
                    } else if (scoreSet.getTag().equals("物理刷题正确率")) {
                        //物理刷题正确率
                        try {
                            List<MathChaPlan> mathChaPlanList = iTeacherFeignClient.getPhysicsPassRadeListIFeign(null, yearPart.toString(), quarterNum.toString(), "1", i.toString(), i.toString(), String.valueOf(yearClassId), null, null, "1", LocalDate.now().toString(), LocalDate.now().toString(), LocalDate.now().toString(), "3", "", "", null, null, "2", teacherId, null, null, null, null, null, null, "2", null, null, null, null);

                            for (MathChaPlan mathChaPlan : mathChaPlanList) {
                                if (mathChaPlan.getRightNumAll() == null || mathChaPlan.getLowestShutnumAll() == null) {
                                    continue;
                                }
                                SenateScoreView senateScore = new SenateScoreView();
                                BigDecimal arrivalCount = new BigDecimal(mathChaPlan.getRightNumAll());
                                BigDecimal studentAllCount = new BigDecimal(mathChaPlan.getLowestShutnumAll());
                                if (studentAllCount.equals(BigDecimal.ZERO)) {
                                    continue;
                                }
                                BigDecimal rade = arrivalCount.divide(studentAllCount, 4, BigDecimal.ROUND_HALF_UP);
                                rade = rade.multiply(new BigDecimal(100));
                                senateScore.setRadeNum(rade);
                                senateScore.setCount(arrivalCount);
                                senateScore.setAllCount(studentAllCount);
                                senateScore.setProjectsId(scoreSet.getSenateProjectId());
                                senateScore.setLessonNum(i);
                                senateScore.setTeacherId(mathChaPlan.getTeacherId());
                                senateScore.setType(1);
                                senateScore.setSubjectsId(scoreSet.getSubjectsId());
                                senateScore.setYearPart(yearPart);
                                senateScore.setQuarterNum(quarterNum);
                                senateScore.setScoreType(1);// 根据senate_depart_score_set表，1个人，2战队
                                senateScore.setType(1);
                                senateScore.setYearClassId(yearClassId);
                                senateScore.setTag("物理刷题正确率");
                                iSenateScoreService.addOrUpdateSenateScoreDataNew(senateScore);
                            }
                        } catch (Exception e) {
                        }
                    }
                }
            }
        }
    }


    /**
     * 战队教务积分统计（新）
     */
    @Override
    public void integralStatisticsActionTeamNew(IntegralStatisticsRs integralStatisticsRs) {
        Integer yearPart = integralStatisticsRs.getYearPart();
        Integer quarterNum = integralStatisticsRs.getQuarterNum();

        Integer startLessonNum = 0;
        Integer endLessonNum = 0;

        if (integralStatisticsRs.getStartLessonNum() != null && integralStatisticsRs.getEndLessonNum() != null) {
            startLessonNum = integralStatisticsRs.getStartLessonNum();
            endLessonNum = integralStatisticsRs.getEndLessonNum();
        } else {
            Integer lessonMax = iRecordCourseService.getMaxLessonNumForInClass(yearPart, quarterNum, 1);
            if (lessonMax != null) {
                startLessonNum = 1;
                endLessonNum = lessonMax;
            }
        }

        QueryWrapper<SenateDepartScoreSet> senateDepartScoreSetQueryWrapper = new QueryWrapper<>();
        senateDepartScoreSetQueryWrapper.eq("year_part", yearPart);
        senateDepartScoreSetQueryWrapper.eq("quarter_num", quarterNum);
        senateDepartScoreSetQueryWrapper.eq("score_type", 2);
        senateDepartScoreSetQueryWrapper.orderByDesc("senate_project_id");
        List<SenateDepartScoreSet> senateDepartScoreSets = iSenateDepartScoreSetService.list(senateDepartScoreSetQueryWrapper);

        LocalDate dateNow = LocalDate.now();

        String senateDepartId = iSenateDepartService.getSenateDepartIdStr();
        QueryWrapper<TrackMarket> trackMarketQueryWrapper = new QueryWrapper<>();
        trackMarketQueryWrapper.eq("year_part", yearPart);
        trackMarketQueryWrapper.eq("quarter_num", quarterNum);
        trackMarketQueryWrapper.eq("track_type", 2);
        trackMarketQueryWrapper.eq("pid", 0);
        trackMarketQueryWrapper.inSql(StringUtils.isNotBlank(senateDepartId), "classify", senateDepartId);
        trackMarketQueryWrapper.groupBy("school_type");
        trackMarketQueryWrapper.orderByAsc("school_type");
        List<TrackMarket> trackMarketList = iTrackMarketService.list(trackMarketQueryWrapper);

        Integer type = 6;
        Integer schoolType = 1;

        for (TrackMarket trackMarket : trackMarketList) {
            if (trackMarket.getSchoolType() == 2) {
                // 大战队按照校区的
                type = 4;
                schoolType = 2;
            }

            for (Integer i = startLessonNum; i <= endLessonNum; i++) {
                for (SenateDepartScoreSet scoreSet : senateDepartScoreSets) {
                    //全部精品课到课率
                    if (scoreSet.getTag().equals("全部精品课到课率")) {
                        try {
                            List<ArrivalRate> arrivalRateList = iTeacherFeignClient.arrivalRate(type, null, null, null, dateNow.toString(), dateNow.toString(), null, null, "2", null, null, yearPart.toString(), quarterNum.toString(), null, null, null, null, "1", null, i.toString(), i.toString(), null, null, "0", "0");

                            HashMap<Long, Integer> rankingMap = new HashMap<>();
                            List<RankedArrivalRate> rankedList = new ArrayList<>();

                            for (ArrivalRate arrivalRate : arrivalRateList) {
                                BigDecimal arrivalCount = new BigDecimal(arrivalRate.getArrivedCount());
                                BigDecimal studentAllCount = new BigDecimal(arrivalRate.getStudentAllCount());
                                if (studentAllCount.equals(BigDecimal.ZERO)) {
                                    continue;
                                }
                                BigDecimal rade = arrivalCount.divide(studentAllCount, 4, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));

                                rankedList.add(new RankedArrivalRate(arrivalRate.getSchoolId(), rade));
                            }

                            rankedList.sort((a, b) -> b.getRade().compareTo(a.getRade()));

                            int currentRank = 0;
                            BigDecimal lastRade = null;
                            for (int rank = 0; rank < rankedList.size(); rank++) {
                                RankedArrivalRate current = rankedList.get(rank);
                                if (lastRade == null || lastRade.compareTo(current.getRade()) != 0) {
                                    currentRank = rank + 1;
                                }
                                rankingMap.put(current.getSchoolId(), currentRank);
                                lastRade = current.getRade();
                            }

                            for (ArrivalRate arrivalRate : arrivalRateList) {
                                SenateScoreView senateScore = new SenateScoreView();
                                if (arrivalRate.getStudentAllCount() == 0) {
                                    continue;
                                }
                                Integer rank = rankingMap.get(arrivalRate.getSchoolId());

                                senateScore.setRadeNum(BigDecimal.valueOf(rank));
                                senateScore.setProjectsId(scoreSet.getSenateProjectId());//到课率
                                senateScore.setLessonNum(i);
                                senateScore.setYearPart(yearPart);
                                senateScore.setQuarterNum(quarterNum);
                                senateScore.setScoreType(2);// 根据senate_depart_score_set表，1个人，2战队
                                senateScore.setSchoolType(schoolType);
                                senateScore.setType(5);
                                senateScore.setTag("全部精品课到课率");
                                senateScore.setSchoolId(arrivalRate.getSchoolId());
                                senateScore.setClassify(scoreSet.getSenateDepartId());
                                iSenateScoreService.addOrUpdateSenateScoreDataNew(senateScore);
                            }
                        } catch (Exception e) {
                        }
               /*  } else if (scoreSet.getTag().equals("英语智能课到课率")) {
                    // 英语智能课到课率
                    List<ArrivalRate> arrivalRateList = iTeacherFeignClient.arrivalRate(type, null, "1", null, dateNow.toString(), dateNow.toString(), null, null, "2", null, null, yearPart.toString(), quarterNum.toString(), null, null, null, null, "2", null, i.toString(), i.toString(), null, null, "0", "0");

                    HashMap<Long, Integer> rankingMap = new HashMap<>();
                    List<RankedArrivalRate> rankedList = new ArrayList<>();

                    for (ArrivalRate arrivalRate : arrivalRateList) {
                        BigDecimal arrivalCount = new BigDecimal(arrivalRate.getArrivedCount());
                        BigDecimal studentAllCount = new BigDecimal(arrivalRate.getStudentAllCount());
                        if (studentAllCount.equals(BigDecimal.ZERO)) {
                            continue;
                        }
                        BigDecimal rade = arrivalCount.divide(studentAllCount, 4, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));

                        rankedList.add(new RankedArrivalRate(arrivalRate.getSchoolId(), rade));
                    }

                    rankedList.sort((a, b) -> b.getRade().compareTo(a.getRade()));

                    int currentRank = 0;
                    BigDecimal lastRade = null;
                    for (int rank = 0; rank < rankedList.size(); rank++) {
                        RankedArrivalRate current = rankedList.get(rank);
                        if (lastRade == null || lastRade.compareTo(current.getRade()) != 0) {
                            currentRank = rank + 1;
                        }
                        rankingMap.put(current.getSchoolId(), currentRank);
                        lastRade = current.getRade();
                    }

                    for (ArrivalRate arrivalRate : arrivalRateList) {
                        //try {
                        SenateScoreView senateScore = new SenateScoreView();
                        if (arrivalRate.getStudentAllCount() == 0) {
                            continue;
                        }
                        Integer rank = rankingMap.get(arrivalRate.getSchoolId());

                        senateScore.setRadeNum(BigDecimal.valueOf(rank));
                        senateScore.setProjectsId(scoreSet.getSenateProjectId());//到课率
                        senateScore.setLessonNum(i);
                        senateScore.setType(5);
                        senateScore.setYearPart(yearPart);
                        senateScore.setQuarterNum(quarterNum);
                        senateScore.setScoreType(2);// 根据senate_depart_score_set表，1个人，2战队
                        senateScore.setSchoolType(schoolType);
                        senateScore.setTag("英语智能课到课率");
                        senateScore.setSchoolId(arrivalRate.getSchoolId());
                        senateScore.setClassify(scoreSet.getSenateDepartId());
                        iSenateScoreService.addOrUpdateSenateScoreDataNew(senateScore);
                        //} catch (Exception e) {
                        // }
                    }

                } else if (scoreSet.getTag().equals("数学刷题到课率")) {
                    // 数学刷题到课率
                    List<ArrivalRate> arrivalRateList = iTeacherFeignClient.arrivalRate(type, null, "2", null, dateNow.toString(), dateNow.toString(), null, null, "2", null, null, yearPart.toString(), quarterNum.toString(), null, null, null, null, "3", null, i.toString(), i.toString(), null, null,"0","0");

                    HashMap<Long, Integer> rankingMap = new HashMap<>();
                    List<RankedArrivalRate> rankedList = new ArrayList<>();

                    for (ArrivalRate arrivalRate : arrivalRateList) {
                        BigDecimal arrivalCount = new BigDecimal(arrivalRate.getArrivedCount());
                        BigDecimal studentAllCount = new BigDecimal(arrivalRate.getStudentAllCount());
                        if (studentAllCount.equals(BigDecimal.ZERO)) {
                            continue;
                        }
                        BigDecimal rade = arrivalCount.divide(studentAllCount, 4, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));

                        rankedList.add(new RankedArrivalRate(arrivalRate.getSchoolId(), rade));
                    }

                    rankedList.sort((a, b) -> b.getRade().compareTo(a.getRade()));

                    int currentRank = 0;
                    BigDecimal lastRade = null;
                    for (int rank = 0; rank < rankedList.size(); rank++) {
                        RankedArrivalRate current = rankedList.get(rank);
                        if (lastRade == null || lastRade.compareTo(current.getRade()) != 0) {
                            currentRank = rank + 1;
                        }
                        rankingMap.put(current.getSchoolId(), currentRank);
                        lastRade = current.getRade();
                    }

                    for (ArrivalRate arrivalRate : arrivalRateList) {
                        //try {
                        SenateScoreView senateScore = new SenateScoreView();
                        if (arrivalRate.getStudentAllCount() == 0) {
                            continue;
                        }
                        Integer rank = rankingMap.get(arrivalRate.getSchoolId());

                        senateScore.setRadeNum(BigDecimal.valueOf(rank));
                        senateScore.setProjectsId(scoreSet.getSenateProjectId());//到课率
                        senateScore.setLessonNum(i);
                        senateScore.setType(5);
                        senateScore.setYearPart(yearPart);
                        senateScore.setQuarterNum(quarterNum);
                        senateScore.setScoreType(2);// 根据senate_depart_score_set表，1个人，2战队
                        senateScore.setSchoolType(schoolType);
                        senateScore.setTag("数学刷题到课率");
                        senateScore.setSchoolId(arrivalRate.getSchoolId());
                        senateScore.setClassify(scoreSet.getSenateDepartId());
                        iSenateScoreService.addOrUpdateSenateScoreDataNew(senateScore);
                        //} catch (Exception e) {
                        // }
                    }
                } else if (scoreSet.getTag().equals("物理刷题到课率")) {
                    // 物理刷题到课率
                    List<ArrivalRate> arrivalRateList = iTeacherFeignClient.arrivalRate(type, null, "3", null, dateNow.toString(), dateNow.toString(), null, null, "2", null, null, yearPart.toString(), quarterNum.toString(), null, null, null, null, "3", null, i.toString(), i.toString(), null, null,"0","0");

                    HashMap<Long, Integer> rankingMap = new HashMap<>();
                    List<RankedArrivalRate> rankedList = new ArrayList<>();

                    for (ArrivalRate arrivalRate : arrivalRateList) {
                        BigDecimal arrivalCount = new BigDecimal(arrivalRate.getArrivedCount());
                        BigDecimal studentAllCount = new BigDecimal(arrivalRate.getStudentAllCount());
                        if (studentAllCount.equals(BigDecimal.ZERO)) {
                            continue;
                        }
                        BigDecimal rade = arrivalCount.divide(studentAllCount, 4, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));

                        rankedList.add(new RankedArrivalRate(arrivalRate.getSchoolId(), rade));
                    }

                    rankedList.sort((a, b) -> b.getRade().compareTo(a.getRade()));

                    int currentRank = 0;
                    BigDecimal lastRade = null;
                    for (int rank = 0; rank < rankedList.size(); rank++) {
                        RankedArrivalRate current = rankedList.get(rank);
                        if (lastRade == null || lastRade.compareTo(current.getRade()) != 0) {
                            currentRank = rank + 1;
                        }
                        rankingMap.put(current.getSchoolId(), currentRank);
                        lastRade = current.getRade();
                    }

                    for (ArrivalRate arrivalRate : arrivalRateList) {
                        //try {
                        SenateScoreView senateScore = new SenateScoreView();
                        if (arrivalRate.getStudentAllCount() == 0) {
                            continue;
                        }
                        Integer rank = rankingMap.get(arrivalRate.getSchoolId());

                        senateScore.setRadeNum(BigDecimal.valueOf(rank));
                        senateScore.setProjectsId(scoreSet.getSenateProjectId());//到课率
                        senateScore.setLessonNum(i);
                        senateScore.setType(5);
                        senateScore.setYearPart(yearPart);
                        senateScore.setQuarterNum(quarterNum);
                        senateScore.setScoreType(2);// 根据senate_depart_score_set表，1个人，2战队
                        senateScore.setSchoolType(schoolType);
                        senateScore.setTag("物理刷题到课率");
                        senateScore.setSchoolId(arrivalRate.getSchoolId());
                        senateScore.setClassify(scoreSet.getSenateDepartId());
                        iSenateScoreService.addOrUpdateSenateScoreDataNew(senateScore);
                        //} catch (Exception e) {
                        // }
                    }*/

                    } else if (scoreSet.getTag().equals("全部精品课准时率")) {
                        //全部精品课准时率
                        try {
                            List<ArrivalRate> arrivalRateList = iTeacherFeignClient.tardinessRateIFeign(yearPart.toString(), quarterNum.toString(), null, null, null, null, "1", i.toString(), i.toString(), null, "1", null, "5", "2", null, null, LocalDate.now().toString(), LocalDate.now().toString(), null, type, null, null, "0", "0");
                            HashMap<Long, Integer> rankingMap = new HashMap<>();
                            List<RankedArrivalRate> rankedList = new ArrayList<>();

                            for (ArrivalRate arrivalRate : arrivalRateList) {
                                BigDecimal arrivalCount = new BigDecimal(arrivalRate.getStudentAllCount() - arrivalRate.getTardinessRateCount() - arrivalRate.getLeaveCount());
                                BigDecimal studentAllCount = new BigDecimal(arrivalRate.getStudentAllCount());
                                if (studentAllCount.equals(BigDecimal.ZERO)) {
                                    continue;
                                }
                                BigDecimal rade = arrivalCount.divide(studentAllCount, 4, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));

                                rankedList.add(new RankedArrivalRate(arrivalRate.getSchoolId(), rade));
                            }

                            rankedList.sort((a, b) -> b.getRade().compareTo(a.getRade()));

                            int currentRank = 0;
                            BigDecimal lastRade = null;
                            for (int rank = 0; rank < rankedList.size(); rank++) {
                                RankedArrivalRate current = rankedList.get(rank);
                                if (lastRade == null || lastRade.compareTo(current.getRade()) != 0) {
                                    currentRank = rank + 1;
                                }
                                rankingMap.put(current.getSchoolId(), currentRank);
                                lastRade = current.getRade();
                            }


                            for (ArrivalRate arrivalRate : arrivalRateList) {

                                SenateScoreView senateScore = new SenateScoreView();
                                if (arrivalRate.getStudentAllCount() == 0) {
                                    continue;
                                }
                                Integer rank = rankingMap.get(arrivalRate.getSchoolId());

                                senateScore.setRadeNum(BigDecimal.valueOf(rank));
                                senateScore.setProjectsId(scoreSet.getSenateProjectId());//到课率
                                senateScore.setLessonNum(i);
                                senateScore.setType(5);
                                senateScore.setYearPart(yearPart);
                                senateScore.setQuarterNum(quarterNum);
                                senateScore.setScoreType(2);// 根据senate_depart_score_set表，1个人，2战队
                                senateScore.setSchoolType(schoolType);
                                senateScore.setTag("全部精品课准时率");
                                senateScore.setSchoolId(arrivalRate.getSchoolId());
                                senateScore.setClassify(scoreSet.getSenateDepartId());
                                iSenateScoreService.addOrUpdateSenateScoreDataNew(senateScore);
                            }
                        } catch (Exception e) {
                        }
                    } else if (scoreSet.getTag().equals("英语智能课通关率")) {
                        //英语智能课通关率
                        try {
                            List<PassRade> radeList = iTeacherFeignClient.getMinimumTaskProgressRateIFeign(yearPart.toString(), quarterNum.toString(), null, null, null, type, 1, "1", null, LocalDate.now().toString(), LocalDate.now().toString(), null, null, null, "7", "2", i, i, null, null);

                            HashMap<Long, Integer> rankingMap = new HashMap<>();
                            List<RankedArrivalRate> rankedList = new ArrayList<>();

                            for (PassRade passRade : radeList) {
                                BigDecimal arrivalCount = new BigDecimal(passRade.getAllStudentNum() - passRade.getNotStudentNum());
                                BigDecimal studentAllCount = new BigDecimal(passRade.getAllStudentNum());
                                if (studentAllCount.equals(BigDecimal.ZERO)) {
                                    continue;
                                }
                                BigDecimal rade = arrivalCount.divide(studentAllCount, 4, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));

                                rankedList.add(new RankedArrivalRate(passRade.getSchoolId(), rade));
                            }

                            rankedList.sort((a, b) -> b.getRade().compareTo(a.getRade()));

                            int currentRank = 0;
                            BigDecimal lastRade = null;
                            for (int rank = 0; rank < rankedList.size(); rank++) {
                                RankedArrivalRate current = rankedList.get(rank);
                                if (lastRade == null || lastRade.compareTo(current.getRade()) != 0) {
                                    currentRank = rank + 1;
                                }
                                rankingMap.put(current.getSchoolId(), currentRank);
                                lastRade = current.getRade();
                            }

                            for (PassRade passRade : radeList) {

                                SenateScoreView senateScore = new SenateScoreView();
                                if (passRade.getAllStudentNum() == 0) {
                                    continue;
                                }
                                Integer rank = rankingMap.get(passRade.getSchoolId());
                                senateScore.setRadeNum(BigDecimal.valueOf(rank));
                                senateScore.setProjectsId(scoreSet.getSenateProjectId());
                                senateScore.setLessonNum(i);
                                senateScore.setType(5);
                                senateScore.setSubjectsId(1L);
                                senateScore.setYearPart(yearPart);
                                senateScore.setQuarterNum(quarterNum);
                                senateScore.setTag("英语智能课通关率");
                                senateScore.setScoreType(2);// 根据senate_depart_score_set表，1个人，2战队
                                senateScore.setSchoolType(schoolType);
                                senateScore.setSchoolId(passRade.getSchoolId());
                                senateScore.setClassify(scoreSet.getSenateDepartId());
                                iSenateScoreService.addOrUpdateSenateScoreDataNew(senateScore);
                            }
                        } catch (Exception e) {
                        }
                    } else if (scoreSet.getTag().equals("英语智能课正确率")) {
                        //英语智能课正确率
                        try {
                            List<PassRade> radeList = iTeacherFeignClient.getMinimumTaskProgressRateIFeign(yearPart.toString(), quarterNum.toString(), null, null, null, type, 1, "1", null, LocalDate.now().toString(), LocalDate.now().toString(), null, null, null, "7", "2", i, i, null, null);

                            HashMap<Long, Integer> rankingMap = new HashMap<>();
                            List<RankedArrivalRate> rankedList = new ArrayList<>();

                            for (PassRade passRade : radeList) {
                                BigDecimal arrivalCount = new BigDecimal(passRade.getFirstRightCount());
                                BigDecimal studentAllCount = new BigDecimal(passRade.getFirstWordCount());
                                if (studentAllCount.equals(BigDecimal.ZERO)) {
                                    continue;
                                }
                                BigDecimal rade = arrivalCount.divide(studentAllCount, 4, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));

                                rankedList.add(new RankedArrivalRate(passRade.getSchoolId(), rade));
                            }

                            rankedList.sort((a, b) -> b.getRade().compareTo(a.getRade()));

                            int currentRank = 0;
                            BigDecimal lastRade = null;
                            for (int rank = 0; rank < rankedList.size(); rank++) {
                                RankedArrivalRate current = rankedList.get(rank);
                                if (lastRade == null || lastRade.compareTo(current.getRade()) != 0) {
                                    currentRank = rank + 1;
                                }
                                rankingMap.put(current.getSchoolId(), currentRank);
                                lastRade = current.getRade();
                            }

                            for (PassRade passRade : radeList) {

                                SenateScoreView senateScore = new SenateScoreView();
                                if (passRade.getFirstWordCount() == 0) {
                                    continue;
                                }
                                Integer rank = rankingMap.get(passRade.getSchoolId());
                                senateScore.setRadeNum(BigDecimal.valueOf(rank));
                                senateScore.setProjectsId(scoreSet.getSenateProjectId());
                                senateScore.setLessonNum(i);
                                senateScore.setType(5);
                                senateScore.setSubjectsId(1L);
                                senateScore.setYearPart(yearPart);
                                senateScore.setQuarterNum(quarterNum);
                                senateScore.setTag("英语智能课通关率");
                                senateScore.setScoreType(2);// 根据senate_depart_score_set表，1个人，2战队
                                senateScore.setSchoolType(schoolType);
                                senateScore.setSchoolId(passRade.getSchoolId());
                                senateScore.setClassify(scoreSet.getSenateDepartId());
                                iSenateScoreService.addOrUpdateSenateScoreDataNew(senateScore);
                            }
                        } catch (Exception e) {
                        }
                    } else if (scoreSet.getTag().equals("数学刷题通关率")) {
                        //数学刷题通关率
                        try {
                            List<MathChaPlan> mathChaPlanList = iTeacherFeignClient.getPassRadeListIFeign(null, yearPart.toString(), quarterNum.toString(), String.valueOf(type), i.toString(), i.toString(), null, null, null, "1", LocalDate.now().toString(), LocalDate.now().toString(), LocalDate.now().toString(), "2", "", "", null, null, "1", null, null, null, null, null, null, null, "1", null, null, null, null);

                            HashMap<Long, Integer> rankingMap = new HashMap<>();
                            List<RankedArrivalRate> rankedList = new ArrayList<>();

                            for (MathChaPlan mathChaPlan : mathChaPlanList) {
                                BigDecimal arrivalCount = new BigDecimal(mathChaPlan.getYetFinishCount2());
                                BigDecimal studentAllCount = new BigDecimal(mathChaPlan.getShowPassNum());
                                if (studentAllCount.equals(BigDecimal.ZERO)) {
                                    continue;
                                }
                                BigDecimal rade = arrivalCount.divide(studentAllCount, 4, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));

                                rankedList.add(new RankedArrivalRate(mathChaPlan.getSchoolId(), rade));
                            }

                            rankedList.sort((a, b) -> b.getRade().compareTo(a.getRade()));

                            int currentRank = 0;
                            BigDecimal lastRade = null;
                            for (int rank = 0; rank < rankedList.size(); rank++) {
                                RankedArrivalRate current = rankedList.get(rank);
                                if (lastRade == null || lastRade.compareTo(current.getRade()) != 0) {
                                    currentRank = rank + 1;
                                }
                                rankingMap.put(current.getSchoolId(), currentRank);
                                lastRade = current.getRade();
                            }

                            for (MathChaPlan mathChaPlan : mathChaPlanList) {

                                SenateScoreView senateScore = new SenateScoreView();
                                if (mathChaPlan.getShowPassNum() == 0) {
                                    continue;
                                }
                                Integer rank = rankingMap.get(mathChaPlan.getSchoolId());

                                senateScore.setRadeNum(BigDecimal.valueOf(rank));
                                senateScore.setProjectsId(scoreSet.getSenateProjectId());
                                senateScore.setLessonNum(i);
                                senateScore.setType(5);
                                senateScore.setSubjectsId(2L);
                                senateScore.setYearPart(yearPart);
                                senateScore.setQuarterNum(quarterNum);
                                senateScore.setTag("数学刷题通关率");
                                senateScore.setScoreType(2);// 根据senate_depart_score_set表，1个人，2战队
                                senateScore.setSchoolType(schoolType);
                                senateScore.setSchoolId(mathChaPlan.getSchoolId());
                                senateScore.setClassify(scoreSet.getSenateDepartId());
                                iSenateScoreService.addOrUpdateSenateScoreDataNew(senateScore);
                            }
                        } catch (Exception e) {
                        }
                    } else if (scoreSet.getTag().equals("数学刷题正确率")) {
                        //数学刷题正确率
                        try {
                            List<MathChaPlan> mathChaPlanList = iTeacherFeignClient.getPassRadeListIFeign(null, yearPart.toString(), quarterNum.toString(), String.valueOf(type), i.toString(), i.toString(), null, null, null, "1", LocalDate.now().toString(), LocalDate.now().toString(), LocalDate.now().toString(), "2", "", "", null, null, "2", null, null, null, null, null, null, null, "2", null, null, null, null);

                            HashMap<Long, Integer> rankingMap = new HashMap<>();
                            List<RankedArrivalRate> rankedList = new ArrayList<>();

                            for (MathChaPlan mathChaPlan : mathChaPlanList) {
                                BigDecimal arrivalCount = new BigDecimal(mathChaPlan.getRightNumAll());
                                BigDecimal studentAllCount = new BigDecimal(mathChaPlan.getLowestShutnumAll());
                                if (studentAllCount.equals(BigDecimal.ZERO)) {
                                    continue;
                                }
                                BigDecimal rade = arrivalCount.divide(studentAllCount, 4, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));

                                rankedList.add(new RankedArrivalRate(mathChaPlan.getSchoolId(), rade));
                            }

                            rankedList.sort((a, b) -> b.getRade().compareTo(a.getRade()));

                            int currentRank = 0;
                            BigDecimal lastRade = null;
                            for (int rank = 0; rank < rankedList.size(); rank++) {
                                RankedArrivalRate current = rankedList.get(rank);
                                if (lastRade == null || lastRade.compareTo(current.getRade()) != 0) {
                                    currentRank = rank + 1;
                                }
                                rankingMap.put(current.getSchoolId(), currentRank);
                                lastRade = current.getRade();
                            }

                            for (MathChaPlan mathChaPlan : mathChaPlanList) {

                                SenateScoreView senateScore = new SenateScoreView();
                                if (mathChaPlan.getLowestShutnumAll() == 0) {
                                    continue;
                                }
                                Integer rank = rankingMap.get(mathChaPlan.getSchoolId());

                                senateScore.setRadeNum(BigDecimal.valueOf(rank));
                                senateScore.setProjectsId(scoreSet.getSenateProjectId());
                                senateScore.setLessonNum(i);
                                senateScore.setType(5);
                                senateScore.setSubjectsId(2L);
                                senateScore.setYearPart(yearPart);
                                senateScore.setQuarterNum(quarterNum);
                                senateScore.setTag("数学刷题正确率");
                                senateScore.setScoreType(2);// 根据senate_depart_score_set表，1个人，2战队
                                senateScore.setSchoolType(schoolType);
                                senateScore.setSchoolId(mathChaPlan.getSchoolId());
                                senateScore.setClassify(scoreSet.getSenateDepartId());
                                iSenateScoreService.addOrUpdateSenateScoreDataNew(senateScore);
                            }
                        } catch (Exception e) {
                        }
                    } else if (scoreSet.getTag().equals("物理刷题通关率")) {
                        //物理刷题通关率
                        try {
                            List<MathChaPlan> mathChaPlanList = iTeacherFeignClient.getPhysicsPassRadeListIFeign(null, yearPart.toString(), quarterNum.toString(), String.valueOf(type), i.toString(), i.toString(), null, null, null, "1", LocalDate.now().toString(), LocalDate.now().toString(), LocalDate.now().toString(), "3", "", "", null, null, "1", null, null, null, null, null, null, null, "1", null, null, null, null);

                            HashMap<Long, Integer> rankingMap = new HashMap<>();
                            List<RankedArrivalRate> rankedList = new ArrayList<>();

                            for (MathChaPlan mathChaPlan : mathChaPlanList) {
                                BigDecimal arrivalCount = new BigDecimal(mathChaPlan.getYetFinishCount2());
                                BigDecimal studentAllCount = new BigDecimal(mathChaPlan.getShowPassNum());
                                if (studentAllCount.equals(BigDecimal.ZERO)) {
                                    continue;
                                }
                                BigDecimal rade = arrivalCount.divide(studentAllCount, 4, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));

                                rankedList.add(new RankedArrivalRate(mathChaPlan.getSchoolId(), rade));
                            }

                            rankedList.sort((a, b) -> b.getRade().compareTo(a.getRade()));

                            int currentRank = 0;
                            BigDecimal lastRade = null;
                            for (int rank = 0; rank < rankedList.size(); rank++) {
                                RankedArrivalRate current = rankedList.get(rank);
                                if (lastRade == null || lastRade.compareTo(current.getRade()) != 0) {
                                    currentRank = rank + 1;
                                }
                                rankingMap.put(current.getSchoolId(), currentRank);
                                lastRade = current.getRade();
                            }

                            for (MathChaPlan mathChaPlan : mathChaPlanList) {

                                SenateScoreView senateScore = new SenateScoreView();
                                if (mathChaPlan.getShowPassNum() == 0) {
                                    continue;
                                }
                                Integer rank = rankingMap.get(mathChaPlan.getSchoolId());

                                senateScore.setRadeNum(BigDecimal.valueOf(rank));
                                senateScore.setProjectsId(scoreSet.getSenateProjectId());
                                senateScore.setLessonNum(i);
                                senateScore.setType(5);
                                senateScore.setSubjectsId(3L);
                                senateScore.setYearPart(yearPart);
                                senateScore.setQuarterNum(quarterNum);
                                senateScore.setTag("物理刷题通关率");
                                senateScore.setScoreType(2);// 根据senate_depart_score_set表，1个人，2战队
                                senateScore.setSchoolType(schoolType);
                                senateScore.setSchoolId(mathChaPlan.getSchoolId());
                                senateScore.setClassify(scoreSet.getSenateDepartId());
                                iSenateScoreService.addOrUpdateSenateScoreDataNew(senateScore);
                            }
                        } catch (Exception e) {
                        }
                    } else if (scoreSet.getTag().equals("物理刷题正确率")) {
                        //物理刷题正确率
                        try {
                            List<MathChaPlan> mathChaPlanList = iTeacherFeignClient.getPassRadeListIFeign(null, yearPart.toString(), quarterNum.toString(), String.valueOf(type), i.toString(), i.toString(), null, null, null, "1", LocalDate.now().toString(), LocalDate.now().toString(), LocalDate.now().toString(), "3", "", "", null, null, "2", null, null, null, null, null, null, null, "2", null, null, null, null);

                            HashMap<Long, Integer> rankingMap = new HashMap<>();
                            List<RankedArrivalRate> rankedList = new ArrayList<>();

                            for (MathChaPlan mathChaPlan : mathChaPlanList) {
                                BigDecimal arrivalCount = new BigDecimal(mathChaPlan.getRightNumAll());
                                BigDecimal studentAllCount = new BigDecimal(mathChaPlan.getLowestShutnumAll());
                                if (studentAllCount.equals(BigDecimal.ZERO)) {
                                    continue;
                                }
                                BigDecimal rade = arrivalCount.divide(studentAllCount, 4, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));

                                rankedList.add(new RankedArrivalRate(mathChaPlan.getSchoolId(), rade));
                            }

                            rankedList.sort((a, b) -> b.getRade().compareTo(a.getRade()));

                            int currentRank = 0;
                            BigDecimal lastRade = null;
                            for (int rank = 0; rank < rankedList.size(); rank++) {
                                RankedArrivalRate current = rankedList.get(rank);
                                if (lastRade == null || lastRade.compareTo(current.getRade()) != 0) {
                                    currentRank = rank + 1;
                                }
                                rankingMap.put(current.getSchoolId(), currentRank);
                                lastRade = current.getRade();
                            }

                            for (MathChaPlan mathChaPlan : mathChaPlanList) {
                                SenateScoreView senateScore = new SenateScoreView();
                                if (mathChaPlan.getLowestShutnumAll() == 0) {
                                    continue;
                                }
                                Integer rank = rankingMap.get(mathChaPlan.getSchoolId());

                                senateScore.setRadeNum(BigDecimal.valueOf(rank));
                                senateScore.setProjectsId(scoreSet.getSenateProjectId());
                                senateScore.setLessonNum(i);
                                senateScore.setType(5);
                                senateScore.setSubjectsId(3L);
                                senateScore.setYearPart(yearPart);
                                senateScore.setQuarterNum(quarterNum);
                                senateScore.setTag("物理刷题正确率");
                                senateScore.setScoreType(2);// 根据senate_depart_score_set表，1个人，2战队
                                senateScore.setSchoolType(schoolType);
                                senateScore.setSchoolId(mathChaPlan.getSchoolId());
                                senateScore.setClassify(scoreSet.getSenateDepartId());
                                iSenateScoreService.addOrUpdateSenateScoreDataNew(senateScore);
                            }
                        } catch (Exception e) {
                        }
                    }
                }
            }
        }


        // 年级率,小战队按照校区、年级查询
        type = 4;
        schoolType = 2;
        for (Integer yearClassId = 0; yearClassId <= 12; yearClassId++) {
            for (Integer i = startLessonNum; i <= endLessonNum; i++) {
                for (SenateDepartScoreSet scoreSet : senateDepartScoreSets) {
                    //全部精品课到课率
                    if (scoreSet.getTag().equals("全部精品课到课率")) {
                        try {
                            List<ArrivalRate> arrivalRateList = iTeacherFeignClient.arrivalRate(type, null, null, null, dateNow.toString(), dateNow.toString(), null, null, "2", null, null, yearPart.toString(), quarterNum.toString(), null, null, null, String.valueOf(yearClassId), "1", null, i.toString(), i.toString(), null, null, "0", "0");

                            HashMap<Long, Integer> rankingMap = new HashMap<>();
                            List<RankedArrivalRate> rankedList = new ArrayList<>();

                            for (ArrivalRate arrivalRate : arrivalRateList) {
                                BigDecimal arrivalCount = new BigDecimal(arrivalRate.getArrivedCount());
                                BigDecimal studentAllCount = new BigDecimal(arrivalRate.getStudentAllCount());
                                if (studentAllCount.equals(BigDecimal.ZERO)) {
                                    continue;
                                }
                                BigDecimal rade = arrivalCount.divide(studentAllCount, 4, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));

                                rankedList.add(new RankedArrivalRate(arrivalRate.getSchoolId(), rade));
                            }

                            rankedList.sort((a, b) -> b.getRade().compareTo(a.getRade()));

                            int currentRank = 0;
                            BigDecimal lastRade = null;
                            for (int rank = 0; rank < rankedList.size(); rank++) {
                                RankedArrivalRate current = rankedList.get(rank);
                                if (lastRade == null || lastRade.compareTo(current.getRade()) != 0) {
                                    currentRank = rank + 1;
                                }
                                rankingMap.put(current.getSchoolId(), currentRank);
                                lastRade = current.getRade();
                            }

                            for (ArrivalRate arrivalRate : arrivalRateList) {

                                SenateScoreView senateScore = new SenateScoreView();
                                if (arrivalRate.getStudentAllCount() == 0) {
                                    continue;
                                }
                                Integer rank = rankingMap.get(arrivalRate.getSchoolId());

                                senateScore.setRadeNum(BigDecimal.valueOf(rank));
                                senateScore.setProjectsId(scoreSet.getSenateProjectId());//到课率
                                senateScore.setLessonNum(i);
                                senateScore.setYearPart(yearPart);
                                senateScore.setQuarterNum(quarterNum);
                                senateScore.setScoreType(2);// 根据senate_depart_score_set表，1个人，2战队
                                senateScore.setSchoolType(schoolType);
                                senateScore.setType(5);
                                senateScore.setTag("全部精品课到课率");
                                senateScore.setSchoolId(arrivalRate.getSchoolId());
                                senateScore.setYearClassId(yearClassId);
                                senateScore.setClassify(scoreSet.getSenateDepartId());
                                iSenateScoreService.addOrUpdateSenateScoreDataNew(senateScore);
                            }
                        } catch (Exception e) {
                        }
                   /* } else if (scoreSet.getTag().equals("英语智能课到课率")) {
                        // 英语智能课到课率
                        List<ArrivalRate> arrivalRateList = iTeacherFeignClient.arrivalRate(type, null, "1", null, dateNow.toString(), dateNow.toString(), null, null, "2", null, null, yearPart.toString(), quarterNum.toString(), null, null, null, String.valueOf(yearClassId), "2", null, i.toString(), i.toString(), null, null, "0", "0");

                        HashMap<Long, Integer> rankingMap = new HashMap<>();
                        List<RankedArrivalRate> rankedList = new ArrayList<>();

                        for (ArrivalRate arrivalRate : arrivalRateList) {
                            BigDecimal arrivalCount = new BigDecimal(arrivalRate.getArrivedCount());
                            BigDecimal studentAllCount = new BigDecimal(arrivalRate.getStudentAllCount());
                            if (studentAllCount.equals(BigDecimal.ZERO)) {
                                continue;
                            }
                            BigDecimal rade = arrivalCount.divide(studentAllCount, 4, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));

                            rankedList.add(new RankedArrivalRate(arrivalRate.getSchoolId(), rade));
                        }

                        rankedList.sort((a, b) -> b.getRade().compareTo(a.getRade()));

                        int currentRank = 0;
                        BigDecimal lastRade = null;
                        for (int rank = 0; rank < rankedList.size(); rank++) {
                            RankedArrivalRate current = rankedList.get(rank);
                            if (lastRade == null || lastRade.compareTo(current.getRade()) != 0) {
                                currentRank = rank + 1;
                            }
                            rankingMap.put(current.getSchoolId(), currentRank);
                            lastRade = current.getRade();
                        }

                        for (ArrivalRate arrivalRate : arrivalRateList) {
                            //try {
                            SenateScoreView senateScore = new SenateScoreView();
                            if (arrivalRate.getStudentAllCount() == 0) {
                                continue;
                            }
                            Integer rank = rankingMap.get(arrivalRate.getSchoolId());

                            senateScore.setRadeNum(BigDecimal.valueOf(rank));
                            senateScore.setProjectsId(scoreSet.getSenateProjectId());//到课率
                            senateScore.setLessonNum(i);
                            senateScore.setType(5);
                            senateScore.setYearPart(yearPart);
                            senateScore.setQuarterNum(quarterNum);
                            senateScore.setScoreType(2);// 根据senate_depart_score_set表，1个人，2战队
                            senateScore.setSchoolType(schoolType);
                            senateScore.setTag("英语智能课到课率");
                            senateScore.setSchoolId(arrivalRate.getSchoolId());
                            senateScore.setYearClassId(yearClassId);
                            senateScore.setClassify(scoreSet.getSenateDepartId());
                            iSenateScoreService.addOrUpdateSenateScoreDataNew(senateScore);
                            //} catch (Exception e) {
                            // }
                        }

                    } else if (scoreSet.getTag().equals("数学刷题到课率")) {
                        // 数学刷题到课率
                        List<ArrivalRate> arrivalRateList = iTeacherFeignClient.arrivalRate(type, null, "2", null, dateNow.toString(), dateNow.toString(), null, null, "2", null, null, yearPart.toString(), quarterNum.toString(), null, null, null, String.valueOf(yearClassId), "3", null, i.toString(), i.toString(), null, null, "0", "0");

                        HashMap<Long, Integer> rankingMap = new HashMap<>();
                        List<RankedArrivalRate> rankedList = new ArrayList<>();

                        for (ArrivalRate arrivalRate : arrivalRateList) {
                            BigDecimal arrivalCount = new BigDecimal(arrivalRate.getArrivedCount());
                            BigDecimal studentAllCount = new BigDecimal(arrivalRate.getStudentAllCount());
                            if (studentAllCount.equals(BigDecimal.ZERO)) {
                                continue;
                            }
                            BigDecimal rade = arrivalCount.divide(studentAllCount, 4, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));

                            rankedList.add(new RankedArrivalRate(arrivalRate.getSchoolId(), rade));
                        }

                        rankedList.sort((a, b) -> b.getRade().compareTo(a.getRade()));

                        int currentRank = 0;
                        BigDecimal lastRade = null;
                        for (int rank = 0; rank < rankedList.size(); rank++) {
                            RankedArrivalRate current = rankedList.get(rank);
                            if (lastRade == null || lastRade.compareTo(current.getRade()) != 0) {
                                currentRank = rank + 1;
                            }
                            rankingMap.put(current.getSchoolId(), currentRank);
                            lastRade = current.getRade();
                        }

                        for (ArrivalRate arrivalRate : arrivalRateList) {
                            //try {
                            SenateScoreView senateScore = new SenateScoreView();
                            if (arrivalRate.getStudentAllCount() == 0) {
                                continue;
                            }
                            Integer rank = rankingMap.get(arrivalRate.getSchoolId());

                            senateScore.setRadeNum(BigDecimal.valueOf(rank));
                            senateScore.setProjectsId(scoreSet.getSenateProjectId());//到课率
                            senateScore.setLessonNum(i);
                            senateScore.setType(5);
                            senateScore.setYearPart(yearPart);
                            senateScore.setQuarterNum(quarterNum);
                            senateScore.setScoreType(2);// 根据senate_depart_score_set表，1个人，2战队
                            senateScore.setSchoolType(schoolType);
                            senateScore.setTag("数学刷题到课率");
                            senateScore.setSchoolId(arrivalRate.getSchoolId());
                            senateScore.setYearClassId(yearClassId);
                            senateScore.setClassify(scoreSet.getSenateDepartId());
                            iSenateScoreService.addOrUpdateSenateScoreDataNew(senateScore);
                            //} catch (Exception e) {
                            // }
                        }
                    } else if (scoreSet.getTag().equals("物理刷题到课率")) {
                        // 物理刷题到课率
                        List<ArrivalRate> arrivalRateList = iTeacherFeignClient.arrivalRate(type, null, "3", null, dateNow.toString(), dateNow.toString(), null, null, "2", null, null, yearPart.toString(), quarterNum.toString(), null, null, null, String.valueOf(yearClassId), "3", null, i.toString(), i.toString(), null, null, "0", "0");

                        HashMap<Long, Integer> rankingMap = new HashMap<>();
                        List<RankedArrivalRate> rankedList = new ArrayList<>();

                        for (ArrivalRate arrivalRate : arrivalRateList) {
                            BigDecimal arrivalCount = new BigDecimal(arrivalRate.getArrivedCount());
                            BigDecimal studentAllCount = new BigDecimal(arrivalRate.getStudentAllCount());
                            if (studentAllCount.equals(BigDecimal.ZERO)) {
                                continue;
                            }
                            BigDecimal rade = arrivalCount.divide(studentAllCount, 4, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));

                            rankedList.add(new RankedArrivalRate(arrivalRate.getSchoolId(), rade));
                        }

                        rankedList.sort((a, b) -> b.getRade().compareTo(a.getRade()));

                        int currentRank = 0;
                        BigDecimal lastRade = null;
                        for (int rank = 0; rank < rankedList.size(); rank++) {
                            RankedArrivalRate current = rankedList.get(rank);
                            if (lastRade == null || lastRade.compareTo(current.getRade()) != 0) {
                                currentRank = rank + 1;
                            }
                            rankingMap.put(current.getSchoolId(), currentRank);
                            lastRade = current.getRade();
                        }

                        for (ArrivalRate arrivalRate : arrivalRateList) {
                            //try {
                            SenateScoreView senateScore = new SenateScoreView();
                            if (arrivalRate.getStudentAllCount() == 0) {
                                continue;
                            }
                            Integer rank = rankingMap.get(arrivalRate.getSchoolId());

                            senateScore.setRadeNum(BigDecimal.valueOf(rank));
                            senateScore.setProjectsId(scoreSet.getSenateProjectId());//到课率
                            senateScore.setLessonNum(i);
                            senateScore.setType(5);
                            senateScore.setYearPart(yearPart);
                            senateScore.setQuarterNum(quarterNum);
                            senateScore.setScoreType(2);// 根据senate_depart_score_set表，1个人，2战队
                            senateScore.setSchoolType(schoolType);
                            senateScore.setTag("物理刷题到课率");
                            senateScore.setSchoolId(arrivalRate.getSchoolId());
                            senateScore.setYearClassId(yearClassId);
                            senateScore.setClassify(scoreSet.getSenateDepartId());
                            iSenateScoreService.addOrUpdateSenateScoreDataNew(senateScore);
                            //} catch (Exception e) {
                            // }
                        }
*/
                    } else if (scoreSet.getTag().equals("全部精品课准时率")) {
                        //全部精品课准时率
                        try {
                            List<ArrivalRate> arrivalRateList = iTeacherFeignClient.tardinessRateIFeign(yearPart.toString(), quarterNum.toString(), null, null, null, String.valueOf(yearClassId), "1", i.toString(), i.toString(), null, "1", null, "5", "2", null, null, LocalDate.now().toString(), LocalDate.now().toString(), null, type, null, null, "0", "0");

                            HashMap<Long, Integer> rankingMap = new HashMap<>();
                            List<RankedArrivalRate> rankedList = new ArrayList<>();

                            for (ArrivalRate arrivalRate : arrivalRateList) {
                                BigDecimal arrivalCount = new BigDecimal(arrivalRate.getStudentAllCount() - arrivalRate.getTardinessRateCount() - arrivalRate.getLeaveCount());
                                BigDecimal studentAllCount = new BigDecimal(arrivalRate.getStudentAllCount());
                                if (studentAllCount.equals(BigDecimal.ZERO)) {
                                    continue;
                                }
                                BigDecimal rade = arrivalCount.divide(studentAllCount, 4, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));

                                rankedList.add(new RankedArrivalRate(arrivalRate.getSchoolId(), rade));
                            }

                            rankedList.sort((a, b) -> b.getRade().compareTo(a.getRade()));

                            int currentRank = 0;
                            BigDecimal lastRade = null;
                            for (int rank = 0; rank < rankedList.size(); rank++) {
                                RankedArrivalRate current = rankedList.get(rank);
                                if (lastRade == null || lastRade.compareTo(current.getRade()) != 0) {
                                    currentRank = rank + 1;
                                }
                                rankingMap.put(current.getSchoolId(), currentRank);
                                lastRade = current.getRade();
                            }

                            for (ArrivalRate arrivalRate : arrivalRateList) {

                                SenateScoreView senateScore = new SenateScoreView();
                                if (arrivalRate.getStudentAllCount() == 0) {
                                    continue;
                                }
                                Integer rank = rankingMap.get(arrivalRate.getSchoolId());

                                senateScore.setRadeNum(BigDecimal.valueOf(rank));
                                senateScore.setProjectsId(scoreSet.getSenateProjectId());//到课率
                                senateScore.setLessonNum(i);
                                senateScore.setType(5);
                                senateScore.setYearPart(yearPart);
                                senateScore.setQuarterNum(quarterNum);
                                senateScore.setScoreType(2);// 根据senate_depart_score_set表，1个人，2战队
                                senateScore.setSchoolType(schoolType);
                                senateScore.setTag("全部精品课准时率");
                                senateScore.setSchoolId(arrivalRate.getSchoolId());
                                senateScore.setYearClassId(yearClassId);
                                senateScore.setClassify(scoreSet.getSenateDepartId());
                                iSenateScoreService.addOrUpdateSenateScoreDataNew(senateScore);
                            }
                        } catch (Exception e) {
                        }
                    } else if (scoreSet.getTag().equals("英语智能课通关率")) {
                        //英语智能课通关率
                        try {
                            List<PassRade> radeList = iTeacherFeignClient.getMinimumTaskProgressRateIFeign(yearPart.toString(), quarterNum.toString(), String.valueOf(yearClassId), null, null, type, 1, "1", null, LocalDate.now().toString(), LocalDate.now().toString(), null, null, null, "7", "2", i, i, null, null);

                            HashMap<Long, Integer> rankingMap = new HashMap<>();
                            List<RankedArrivalRate> rankedList = new ArrayList<>();

                            for (PassRade passRade : radeList) {
                                BigDecimal arrivalCount = new BigDecimal(passRade.getAllStudentNum() - passRade.getNotStudentNum());
                                BigDecimal studentAllCount = new BigDecimal(passRade.getAllStudentNum());
                                if (studentAllCount.equals(BigDecimal.ZERO)) {
                                    continue;
                                }
                                BigDecimal rade = arrivalCount.divide(studentAllCount, 4, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));

                                rankedList.add(new RankedArrivalRate(passRade.getSchoolId(), rade));
                            }

                            rankedList.sort((a, b) -> b.getRade().compareTo(a.getRade()));

                            int currentRank = 0;
                            BigDecimal lastRade = null;
                            for (int rank = 0; rank < rankedList.size(); rank++) {
                                RankedArrivalRate current = rankedList.get(rank);
                                if (lastRade == null || lastRade.compareTo(current.getRade()) != 0) {
                                    currentRank = rank + 1;
                                }
                                rankingMap.put(current.getSchoolId(), currentRank);
                                lastRade = current.getRade();
                            }

                            for (PassRade passRade : radeList) {
                                SenateScoreView senateScore = new SenateScoreView();
                                if (passRade.getAllStudentNum() == 0) {
                                    continue;
                                }
                                Integer rank = rankingMap.get(passRade.getSchoolId());
                                senateScore.setRadeNum(BigDecimal.valueOf(rank));
                                senateScore.setProjectsId(scoreSet.getSenateProjectId());
                                senateScore.setLessonNum(i);
                                senateScore.setType(5);
                                senateScore.setSubjectsId(1L);
                                senateScore.setYearPart(yearPart);
                                senateScore.setQuarterNum(quarterNum);
                                senateScore.setTag("英语智能课通关率");
                                senateScore.setScoreType(2);// 根据senate_depart_score_set表，1个人，2战队
                                senateScore.setSchoolType(schoolType);
                                senateScore.setSchoolId(passRade.getSchoolId());
                                senateScore.setYearClassId(yearClassId);
                                senateScore.setClassify(scoreSet.getSenateDepartId());
                                iSenateScoreService.addOrUpdateSenateScoreDataNew(senateScore);
                            }
                        } catch (Exception e) {
                        }
                    } else if (scoreSet.getTag().equals("英语智能课正确率")) {
                        //英语智能课正确率
                        try {
                            List<PassRade> radeList = iTeacherFeignClient.getMinimumTaskProgressRateIFeign(yearPart.toString(), quarterNum.toString(), String.valueOf(yearClassId), null, null, type, 1, "1", null, LocalDate.now().toString(), LocalDate.now().toString(), null, null, null, "7", "2", i, i, null, null);

                            HashMap<Long, Integer> rankingMap = new HashMap<>();
                            List<RankedArrivalRate> rankedList = new ArrayList<>();

                            for (PassRade passRade : radeList) {
                                BigDecimal arrivalCount = new BigDecimal(passRade.getFirstRightCount());
                                BigDecimal studentAllCount = new BigDecimal(passRade.getFirstWordCount());
                                if (studentAllCount.equals(BigDecimal.ZERO)) {
                                    continue;
                                }
                                BigDecimal rade = arrivalCount.divide(studentAllCount, 4, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));

                                rankedList.add(new RankedArrivalRate(passRade.getSchoolId(), rade));
                            }

                            rankedList.sort((a, b) -> b.getRade().compareTo(a.getRade()));

                            int currentRank = 0;
                            BigDecimal lastRade = null;
                            for (int rank = 0; rank < rankedList.size(); rank++) {
                                RankedArrivalRate current = rankedList.get(rank);
                                if (lastRade == null || lastRade.compareTo(current.getRade()) != 0) {
                                    currentRank = rank + 1;
                                }
                                rankingMap.put(current.getSchoolId(), currentRank);
                                lastRade = current.getRade();
                            }

                            for (PassRade passRade : radeList) {
                                SenateScoreView senateScore = new SenateScoreView();
                                if (passRade.getFirstWordCount() == 0) {
                                    continue;
                                }
                                Integer rank = rankingMap.get(passRade.getSchoolId());
                                senateScore.setRadeNum(BigDecimal.valueOf(rank));
                                senateScore.setProjectsId(scoreSet.getSenateProjectId());
                                senateScore.setLessonNum(i);
                                senateScore.setType(5);
                                senateScore.setSubjectsId(1L);
                                senateScore.setYearPart(yearPart);
                                senateScore.setQuarterNum(quarterNum);
                                senateScore.setTag("英语智能课通关率");
                                senateScore.setScoreType(2);// 根据senate_depart_score_set表，1个人，2战队
                                senateScore.setSchoolType(schoolType);
                                senateScore.setSchoolId(passRade.getSchoolId());
                                senateScore.setYearClassId(yearClassId);
                                senateScore.setClassify(scoreSet.getSenateDepartId());
                                iSenateScoreService.addOrUpdateSenateScoreDataNew(senateScore);
                            }
                        } catch (Exception e) {
                        }
                    } else if (scoreSet.getTag().equals("数学刷题通关率")) {
                        //数学刷题通关率
                        try {
                            List<MathChaPlan> mathChaPlanList = iTeacherFeignClient.getPassRadeListIFeign(null, yearPart.toString(), quarterNum.toString(), String.valueOf(type), i.toString(), i.toString(), String.valueOf(yearClassId), null, null, "1", LocalDate.now().toString(), LocalDate.now().toString(), LocalDate.now().toString(), "2", "", "", null, null, "1", null, null, null, null, null, null, null, "1", null, null, null, null);

                            HashMap<Long, Integer> rankingMap = new HashMap<>();
                            List<RankedArrivalRate> rankedList = new ArrayList<>();

                            for (MathChaPlan mathChaPlan : mathChaPlanList) {
                                BigDecimal arrivalCount = new BigDecimal(mathChaPlan.getYetFinishCount2());
                                BigDecimal studentAllCount = new BigDecimal(mathChaPlan.getShowPassNum());
                                if (studentAllCount.equals(BigDecimal.ZERO)) {
                                    continue;
                                }
                                BigDecimal rade = arrivalCount.divide(studentAllCount, 4, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));

                                rankedList.add(new RankedArrivalRate(mathChaPlan.getSchoolId(), rade));
                            }

                            rankedList.sort((a, b) -> b.getRade().compareTo(a.getRade()));

                            int currentRank = 0;
                            BigDecimal lastRade = null;
                            for (int rank = 0; rank < rankedList.size(); rank++) {
                                RankedArrivalRate current = rankedList.get(rank);
                                if (lastRade == null || lastRade.compareTo(current.getRade()) != 0) {
                                    currentRank = rank + 1;
                                }
                                rankingMap.put(current.getSchoolId(), currentRank);
                                lastRade = current.getRade();
                            }

                            for (MathChaPlan mathChaPlan : mathChaPlanList) {
                                SenateScoreView senateScore = new SenateScoreView();
                                if (mathChaPlan.getShowPassNum() == 0) {
                                    continue;
                                }
                                Integer rank = rankingMap.get(mathChaPlan.getSchoolId());

                                senateScore.setRadeNum(BigDecimal.valueOf(rank));
                                senateScore.setProjectsId(scoreSet.getSenateProjectId());
                                senateScore.setLessonNum(i);
                                senateScore.setType(5);
                                senateScore.setSubjectsId(2L);
                                senateScore.setYearPart(yearPart);
                                senateScore.setQuarterNum(quarterNum);
                                senateScore.setTag("数学刷题通关率");
                                senateScore.setScoreType(2);// 根据senate_depart_score_set表，1个人，2战队
                                senateScore.setSchoolType(schoolType);
                                senateScore.setYearClassId(yearClassId);
                                senateScore.setSchoolId(mathChaPlan.getSchoolId());
                                senateScore.setClassify(scoreSet.getSenateDepartId());
                                iSenateScoreService.addOrUpdateSenateScoreDataNew(senateScore);
                            }
                        } catch (Exception e) {
                        }
                    } else if (scoreSet.getTag().equals("数学刷题正确率")) {
                        //数学刷题正确率
                        try {
                            List<MathChaPlan> mathChaPlanList = iTeacherFeignClient.getPassRadeListIFeign(null, yearPart.toString(), quarterNum.toString(), String.valueOf(type), i.toString(), i.toString(), String.valueOf(yearClassId), null, null, "1", LocalDate.now().toString(), LocalDate.now().toString(), LocalDate.now().toString(), "2", "", "", null, null, "2", null, null, null, null, null, null, null, "2", null, null, null, null);

                            HashMap<Long, Integer> rankingMap = new HashMap<>();
                            List<RankedArrivalRate> rankedList = new ArrayList<>();

                            for (MathChaPlan mathChaPlan : mathChaPlanList) {
                                BigDecimal arrivalCount = new BigDecimal(mathChaPlan.getRightNumAll());
                                BigDecimal studentAllCount = new BigDecimal(mathChaPlan.getLowestShutnumAll());
                                if (studentAllCount.equals(BigDecimal.ZERO)) {
                                    continue;
                                }
                                BigDecimal rade = arrivalCount.divide(studentAllCount, 4, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));

                                rankedList.add(new RankedArrivalRate(mathChaPlan.getSchoolId(), rade));
                            }

                            rankedList.sort((a, b) -> b.getRade().compareTo(a.getRade()));

                            int currentRank = 0;
                            BigDecimal lastRade = null;
                            for (int rank = 0; rank < rankedList.size(); rank++) {
                                RankedArrivalRate current = rankedList.get(rank);
                                if (lastRade == null || lastRade.compareTo(current.getRade()) != 0) {
                                    currentRank = rank + 1;
                                }
                                rankingMap.put(current.getSchoolId(), currentRank);
                                lastRade = current.getRade();
                            }

                            for (MathChaPlan mathChaPlan : mathChaPlanList) {

                                SenateScoreView senateScore = new SenateScoreView();
                                if (mathChaPlan.getLowestShutnumAll() == 0) {
                                    continue;
                                }
                                Integer rank = rankingMap.get(mathChaPlan.getSchoolId());

                                senateScore.setRadeNum(BigDecimal.valueOf(rank));
                                senateScore.setProjectsId(scoreSet.getSenateProjectId());
                                senateScore.setLessonNum(i);
                                senateScore.setType(5);
                                senateScore.setSubjectsId(2L);
                                senateScore.setYearPart(yearPart);
                                senateScore.setQuarterNum(quarterNum);
                                senateScore.setTag("数学刷题正确率");
                                senateScore.setScoreType(2);// 根据senate_depart_score_set表，1个人，2战队
                                senateScore.setSchoolType(schoolType);
                                senateScore.setYearClassId(yearClassId);
                                senateScore.setSchoolId(mathChaPlan.getSchoolId());
                                senateScore.setClassify(scoreSet.getSenateDepartId());
                                iSenateScoreService.addOrUpdateSenateScoreDataNew(senateScore);
                            }
                        } catch (Exception e) {
                        }
                    } else if (scoreSet.getTag().equals("物理刷题通关率")) {
                        //物理刷题通关率
                        try {
                            List<MathChaPlan> mathChaPlanList = iTeacherFeignClient.getPassRadeListIFeign(null, yearPart.toString(), quarterNum.toString(), String.valueOf(type), i.toString(), i.toString(), String.valueOf(yearClassId), null, null, "1", LocalDate.now().toString(), LocalDate.now().toString(), LocalDate.now().toString(), "3", "", "", null, null, "1", null, null, null, null, null, null, null, "1", null, null, null, null);

                            HashMap<Long, Integer> rankingMap = new HashMap<>();
                            List<RankedArrivalRate> rankedList = new ArrayList<>();

                            for (MathChaPlan mathChaPlan : mathChaPlanList) {
                                BigDecimal arrivalCount = new BigDecimal(mathChaPlan.getYetFinishCount2());
                                BigDecimal studentAllCount = new BigDecimal(mathChaPlan.getShowPassNum());
                                if (studentAllCount.equals(BigDecimal.ZERO)) {
                                    continue;
                                }
                                BigDecimal rade = arrivalCount.divide(studentAllCount, 4, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));

                                rankedList.add(new RankedArrivalRate(mathChaPlan.getSchoolId(), rade));
                            }

                            rankedList.sort((a, b) -> b.getRade().compareTo(a.getRade()));

                            int currentRank = 0;
                            BigDecimal lastRade = null;
                            for (int rank = 0; rank < rankedList.size(); rank++) {
                                RankedArrivalRate current = rankedList.get(rank);
                                if (lastRade == null || lastRade.compareTo(current.getRade()) != 0) {
                                    currentRank = rank + 1;
                                }
                                rankingMap.put(current.getSchoolId(), currentRank);
                                lastRade = current.getRade();
                            }

                            for (MathChaPlan mathChaPlan : mathChaPlanList) {
                                SenateScoreView senateScore = new SenateScoreView();
                                if (mathChaPlan.getShowPassNum() == 0) {
                                    continue;
                                }
                                Integer rank = rankingMap.get(mathChaPlan.getSchoolId());

                                senateScore.setRadeNum(BigDecimal.valueOf(rank));
                                senateScore.setProjectsId(scoreSet.getSenateProjectId());
                                senateScore.setLessonNum(i);
                                senateScore.setSubjectsId(3L);
                                senateScore.setYearPart(yearPart);
                                senateScore.setQuarterNum(quarterNum);
                                senateScore.setTag("物理刷题通关率");
                                senateScore.setScoreType(2);// 根据senate_depart_score_set表，1个人，2战队
                                senateScore.setSchoolType(schoolType);
                                senateScore.setType(5);
                                senateScore.setSchoolId(mathChaPlan.getSchoolId());
                                senateScore.setYearClassId(yearClassId);
                                senateScore.setClassify(scoreSet.getSenateDepartId());
                                iSenateScoreService.addOrUpdateSenateScoreDataNew(senateScore);
                            }
                        } catch (Exception e) {
                        }
                    } else if (scoreSet.getTag().equals("物理刷题正确率")) {
                        //物理刷题正确率
                        try {
                            List<MathChaPlan> mathChaPlanList = iTeacherFeignClient.getPhysicsPassRadeListIFeign(null, yearPart.toString(), quarterNum.toString(), String.valueOf(type), i.toString(), i.toString(), String.valueOf(yearClassId), null, null, "1", LocalDate.now().toString(), LocalDate.now().toString(), LocalDate.now().toString(), "3", "", "", null, null, "2", null, null, null, null, null, null, null, "2", null, null, null, null);

                            HashMap<Long, Integer> rankingMap = new HashMap<>();
                            List<RankedArrivalRate> rankedList = new ArrayList<>();

                            for (MathChaPlan mathChaPlan : mathChaPlanList) {
                                BigDecimal arrivalCount = new BigDecimal(mathChaPlan.getRightNumAll());
                                BigDecimal studentAllCount = new BigDecimal(mathChaPlan.getLowestShutnumAll());
                                if (studentAllCount.equals(BigDecimal.ZERO)) {
                                    continue;
                                }
                                BigDecimal rade = arrivalCount.divide(studentAllCount, 4, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));

                                rankedList.add(new RankedArrivalRate(mathChaPlan.getSchoolId(), rade));
                            }

                            rankedList.sort((a, b) -> b.getRade().compareTo(a.getRade()));

                            int currentRank = 0;
                            BigDecimal lastRade = null;
                            for (int rank = 0; rank < rankedList.size(); rank++) {
                                RankedArrivalRate current = rankedList.get(rank);
                                if (lastRade == null || lastRade.compareTo(current.getRade()) != 0) {
                                    currentRank = rank + 1;
                                }
                                rankingMap.put(current.getSchoolId(), currentRank);
                                lastRade = current.getRade();
                            }

                            for (MathChaPlan mathChaPlan : mathChaPlanList) {
                                SenateScoreView senateScore = new SenateScoreView();
                                if (mathChaPlan.getLowestShutnumAll() == 0) {
                                    continue;
                                }
                                Integer rank = rankingMap.get(mathChaPlan.getSchoolId());

                                senateScore.setRadeNum(BigDecimal.valueOf(rank));
                                senateScore.setProjectsId(scoreSet.getSenateProjectId());
                                senateScore.setLessonNum(i);
                                senateScore.setSubjectsId(3L);
                                senateScore.setYearPart(yearPart);
                                senateScore.setQuarterNum(quarterNum);
                                senateScore.setTag("物理刷题正确率");
                                senateScore.setScoreType(2);// 根据senate_depart_score_set表，1个人，2战队
                                senateScore.setSchoolType(schoolType);
                                senateScore.setType(5);
                                senateScore.setSchoolId(mathChaPlan.getSchoolId());
                                senateScore.setYearClassId(yearClassId);
                                senateScore.setClassify(scoreSet.getSenateDepartId());
                                iSenateScoreService.addOrUpdateSenateScoreDataNew(senateScore);
                            }
                        } catch (Exception e) {
                        }
                    }
                }
            }
        }

    }


    /**
     * 基准值统计
     */
    @Override
    public void radeFiducialStatisticsAction(IntegralStatisticsRs integralStatisticsRs) {
        Integer yearPart = integralStatisticsRs.getYearPart();
        Integer quarterNum = integralStatisticsRs.getQuarterNum();

        Integer startLessonNum = 0;
        Integer endLessonNum = 0;
        LocalDate dateNow = LocalDate.now();

        if (integralStatisticsRs.getStartLessonNum() != null && integralStatisticsRs.getEndLessonNum() != null) {
            startLessonNum = integralStatisticsRs.getStartLessonNum();
            endLessonNum = integralStatisticsRs.getEndLessonNum();
        } else {
            Integer lessonMax = iRecordCourseService.getMaxLessonNumForInClass(yearPart, quarterNum, 1);
            if (lessonMax != null) {
                startLessonNum = 1;
                endLessonNum = lessonMax;
            }
        }

        QueryWrapper<RadeFiducialSet> radeFiducialSetQueryWrapper = new QueryWrapper<>();
        radeFiducialSetQueryWrapper.eq("year_part", yearPart);
        radeFiducialSetQueryWrapper.eq("quarter_num", quarterNum);
        radeFiducialSetQueryWrapper.eq("status", 1);
        List<RadeFiducialSet> senateDepartScoreSets = iRadeFiducialSetService.list(radeFiducialSetQueryWrapper);

        Integer type = 6;// 根据四大校区查询

        List<String> subjectIdList = new ArrayList<>();
        subjectIdList.add("");
//        subjectIdList.add("1");
//        subjectIdList.add("2");
//        subjectIdList.add("3");

        List<String> yearClassIdList = new ArrayList<>();
        yearClassIdList.add(YEAR_CLASS_ID_DEFAULT);
//        for (int yearClassId = 0; yearClassId < 13; yearClassId++) {
//            yearClassIdList.add(String.valueOf(yearClassId));
//        }

        for (Integer i = startLessonNum; i <= endLessonNum; i++) {
            for (RadeFiducialSet radeFiducialSet : senateDepartScoreSets) {
                for (String yearClassId : yearClassIdList) {
                    switch (radeFiducialSet.getProjectsName()) {
                        case "精品课到课率":
                            try {
                                List<ArrivalRate> arrivalRateList = iTeacherFeignClient.arrivalRate(type, null, null, null, dateNow.toString(), dateNow.toString(), null, null, "2", null, null, yearPart.toString(), quarterNum.toString(), null, null, null, yearClassId, "1", null, i.toString(), i.toString(), null, null, "0", "0");

                                if (arrivalRateList == null || arrivalRateList.size() == 0) {
                                    continue;
                                }

                                List<RankedArrivalRate> rankedList = new ArrayList<>();
                                for (ArrivalRate arrivalRate : arrivalRateList) {
                                    BigDecimal arrivalCount = new BigDecimal(arrivalRate.getArrivedCount());
                                    BigDecimal studentAllCount = new BigDecimal(arrivalRate.getStudentAllCount());
                                    BigDecimal rade = new BigDecimal(0);
                                    if (!studentAllCount.equals(BigDecimal.ZERO)) {
                                        rade = arrivalCount.divide(studentAllCount, 4, RoundingMode.HALF_UP).multiply(new BigDecimal(100));
                                    }
                                    rankedList.add(new RankedArrivalRate(arrivalRate.getSchoolId(), rade));
                                }

                                this.processRankedArrivalRates(rankedList, yearPart, quarterNum, radeFiducialSet.getLessonType(), i, radeFiducialSet.getProjectsId(), radeFiducialSet.getProjectsName(), type, radeFiducialSet.getSubjectsId(), radeFiducialSet.getId(), null, yearClassId);

                            } catch (Exception ignored) {
                            }
                            break;

                        case "精品课准时率":
                            try {
                                List<ArrivalRate> arrivalRateList = iTeacherFeignClient.tardinessRateIFeign(yearPart.toString(), quarterNum.toString(), null, null, null, yearClassId, "1", i.toString(), i.toString(), null, null, null, "5", "2", null, null, LocalDate.now().toString(), LocalDate.now().toString(), null, type, null, null, "0", "0");

                                if (arrivalRateList == null || arrivalRateList.size() == 0) {
                                    continue;
                                }

                                List<RankedArrivalRate> rankedList = new ArrayList<>();
                                for (ArrivalRate arrivalRate : arrivalRateList) {
                                    BigDecimal arrivalCount = new BigDecimal(arrivalRate.getStudentAllCount() - arrivalRate.getTardinessRateCount() - arrivalRate.getLeaveCount());
                                    BigDecimal studentAllCount = new BigDecimal(arrivalRate.getStudentAllCount());
                                    BigDecimal rade = new BigDecimal(0);
                                    if (!studentAllCount.equals(BigDecimal.ZERO)) {
                                        rade = arrivalCount.divide(studentAllCount, 4, RoundingMode.HALF_UP).multiply(new BigDecimal(100));
                                    }
                                    rankedList.add(new RankedArrivalRate(arrivalRate.getSchoolId(), rade));
                                }

                                this.processRankedArrivalRates(rankedList, yearPart, quarterNum, radeFiducialSet.getLessonType(), i, radeFiducialSet.getProjectsId(), radeFiducialSet.getProjectsName(), type, radeFiducialSet.getSubjectsId(), radeFiducialSet.getId(), null, yearClassId);

                            } catch (Exception ignored) {
                            }
                            break;

                        case "旷课率":
                            try {
                                List<ArrivalRate> arrivalRateList = iTeacherFeignClient.arrivalRate(type, null, null, null, dateNow.toString(), dateNow.toString(), null, null, "2", null, null, yearPart.toString(), quarterNum.toString(), null, null, null, yearClassId, "1", null, i.toString(), i.toString(), null, null, "0", "0");

                                if (arrivalRateList == null || arrivalRateList.size() == 0) {
                                    continue;
                                }

                                List<RankedArrivalRate> rankedList = new ArrayList<>();
                                for (ArrivalRate arrivalRate : arrivalRateList) {
                                    BigDecimal arrivalCount = new BigDecimal(arrivalRate.getNoArrivedCount());
                                    BigDecimal studentAllCount = new BigDecimal(arrivalRate.getStudentAllCount());
                                    BigDecimal rade = new BigDecimal(0);
                                    if (!studentAllCount.equals(BigDecimal.ZERO)) {
                                        rade = arrivalCount.divide(studentAllCount, 4, RoundingMode.HALF_UP).multiply(new BigDecimal(100));
                                    }
                                    rankedList.add(new RankedArrivalRate(arrivalRate.getSchoolId(), rade));
                                }

                                this.processRankedArrivalRates(rankedList, yearPart, quarterNum, radeFiducialSet.getLessonType(), i, radeFiducialSet.getProjectsId(), radeFiducialSet.getProjectsName(), type, radeFiducialSet.getSubjectsId(), radeFiducialSet.getId(), null, yearClassId);

                            } catch (Exception ignored) {
                            }
                            break;

                        case "英语通关率":
                            try {
                                List<PassRade> radeList = iTeacherFeignClient.getMinimumTaskProgressRateIFeign(yearPart.toString(), quarterNum.toString(), yearClassId, null, null, type, 1, "1", null, LocalDate.now().toString(), LocalDate.now().toString(), null, null, null, "7", "2", i, i, null, null);

                                if (radeList == null || radeList.size() == 0) {
                                    continue;
                                }

                                List<RankedArrivalRate> rankedList = new ArrayList<>();
                                for (PassRade passRade : radeList) {
                                    BigDecimal arrivalCount = new BigDecimal(passRade.getAllStudentNum() - passRade.getNotStudentNum());
                                    BigDecimal studentAllCount = new BigDecimal(passRade.getAllStudentNum());
                                    BigDecimal rade = new BigDecimal(0);
                                    if (!studentAllCount.equals(BigDecimal.ZERO)) {
                                        rade = arrivalCount.divide(studentAllCount, 4, RoundingMode.HALF_UP).multiply(new BigDecimal(100));
                                    }
                                    rankedList.add(new RankedArrivalRate(passRade.getSchoolId(), rade));
                                }

                                this.processRankedArrivalRates(rankedList, yearPart, quarterNum, radeFiducialSet.getLessonType(), i, radeFiducialSet.getProjectsId(), radeFiducialSet.getProjectsName(), type, radeFiducialSet.getSubjectsId(), radeFiducialSet.getId(), null, yearClassId);

                            } catch (Exception ignored) {
                            }
                            break;

                        case "英语正确率":
                            try {
                                List<PassRade> radeList = iTeacherFeignClient.getMinimumTaskProgressRateIFeign(yearPart.toString(), quarterNum.toString(), yearClassId, null, null, type, 1, "1", null, LocalDate.now().toString(), LocalDate.now().toString(), null, null, null, "7", "2", i, i, null, null);

                                if (radeList == null || radeList.size() == 0) {
                                    continue;
                                }

                                List<RankedArrivalRate> rankedList = new ArrayList<>();
                                for (PassRade passRade : radeList) {
                                    BigDecimal arrivalCount = new BigDecimal(passRade.getFirstRightCount());
                                    BigDecimal studentAllCount = new BigDecimal(passRade.getFirstWordCount());
                                    BigDecimal rade = new BigDecimal(0);
                                    if (!studentAllCount.equals(BigDecimal.ZERO)) {
                                        rade = arrivalCount.divide(studentAllCount, 4, RoundingMode.HALF_UP).multiply(new BigDecimal(100));
                                    }
                                    rankedList.add(new RankedArrivalRate(passRade.getSchoolId(), rade));
                                }

                                this.processRankedArrivalRates(rankedList, yearPart, quarterNum, radeFiducialSet.getLessonType(), i, radeFiducialSet.getProjectsId(), radeFiducialSet.getProjectsName(), type, radeFiducialSet.getSubjectsId(), radeFiducialSet.getId(), null, yearClassId);

                            } catch (Exception ignored) {
                            }
                            break;

                        case "数学通关率":
                            try {
                                List<MathChaPlan> mathChaPlanList = iTeacherFeignClient.getPassRadeListIFeign(null, yearPart.toString(), quarterNum.toString(), String.valueOf(type), i.toString(), i.toString(), yearClassId, null, null, "1", LocalDate.now().toString(), LocalDate.now().toString(), LocalDate.now().toString(), "2", "", "", null, null, "1", null, null, null, null, null, null, null, "1", null, null, null, null);

                                if (mathChaPlanList == null || mathChaPlanList.size() == 0) {
                                    continue;
                                }

                                List<RankedArrivalRate> rankedList = new ArrayList<>();
                                for (MathChaPlan mathChaPlan : mathChaPlanList) {
                                    BigDecimal arrivalCount = new BigDecimal(mathChaPlan.getYetFinishCount2());
                                    BigDecimal studentAllCount = new BigDecimal(mathChaPlan.getShowPassNum());
                                    BigDecimal rade = new BigDecimal(0);
                                    if (!studentAllCount.equals(BigDecimal.ZERO)) {
                                        rade = arrivalCount.divide(studentAllCount, 4, RoundingMode.HALF_UP).multiply(new BigDecimal(100));
                                    }
                                    rankedList.add(new RankedArrivalRate(mathChaPlan.getSchoolId(), rade));
                                }

                                this.processRankedArrivalRates(rankedList, yearPart, quarterNum, radeFiducialSet.getLessonType(), i, radeFiducialSet.getProjectsId(), radeFiducialSet.getProjectsName(), type, radeFiducialSet.getSubjectsId(), radeFiducialSet.getId(), null, yearClassId);

                            } catch (Exception ignored) {
                            }
                            break;

                        case "数学正确率":
                            try {
                                List<MathChaPlan> mathChaPlanList = iTeacherFeignClient.getPassRadeListIFeign(null, yearPart.toString(), quarterNum.toString(), String.valueOf(type), i.toString(), i.toString(), yearClassId, null, null, "1", LocalDate.now().toString(), LocalDate.now().toString(), LocalDate.now().toString(), "2", "", "", null, null, "2", null, null, null, null, null, null, null, "2", null, null, null, null);

                                if (mathChaPlanList == null || mathChaPlanList.size() == 0) {
                                    continue;
                                }

                                List<RankedArrivalRate> rankedList = new ArrayList<>();
                                for (MathChaPlan mathChaPlan : mathChaPlanList) {
                                    BigDecimal arrivalCount = new BigDecimal(mathChaPlan.getRightNumAll());
                                    BigDecimal studentAllCount = new BigDecimal(mathChaPlan.getLowestShutnumAll());
                                    BigDecimal rade = new BigDecimal(0);
                                    if (!studentAllCount.equals(BigDecimal.ZERO)) {
                                        rade = arrivalCount.divide(studentAllCount, 4, RoundingMode.HALF_UP).multiply(new BigDecimal(100));
                                    }
                                    rankedList.add(new RankedArrivalRate(mathChaPlan.getSchoolId(), rade));
                                }

                                this.processRankedArrivalRates(rankedList, yearPart, quarterNum, radeFiducialSet.getLessonType(), i, radeFiducialSet.getProjectsId(), radeFiducialSet.getProjectsName(), type, radeFiducialSet.getSubjectsId(), radeFiducialSet.getId(), null, yearClassId);

                            } catch (Exception ignored) {
                            }
                            break;

                        case "物理通关率":
                            try {
                                List<MathChaPlan> mathChaPlanList = iTeacherFeignClient.getPhysicsPassRadeListIFeign(null, yearPart.toString(), quarterNum.toString(), String.valueOf(type), i.toString(), i.toString(), yearClassId, null, null, "1", LocalDate.now().toString(), LocalDate.now().toString(), LocalDate.now().toString(), "3", "", "", null, null, "1", null, null, null, null, null, null, null, "1", null, null, null, null);

                                if (mathChaPlanList == null || mathChaPlanList.size() == 0) {
                                    continue;
                                }

                                List<RankedArrivalRate> rankedList = new ArrayList<>();
                                for (MathChaPlan mathChaPlan : mathChaPlanList) {
                                    BigDecimal arrivalCount = new BigDecimal(mathChaPlan.getYetFinishCount2());
                                    BigDecimal studentAllCount = new BigDecimal(mathChaPlan.getShowPassNum());
                                    BigDecimal rade = new BigDecimal(0);
                                    if (!studentAllCount.equals(BigDecimal.ZERO)) {
                                        rade = arrivalCount.divide(studentAllCount, 4, RoundingMode.HALF_UP).multiply(new BigDecimal(100));
                                    }
                                    rankedList.add(new RankedArrivalRate(mathChaPlan.getSchoolId(), rade));
                                }

                                this.processRankedArrivalRates(rankedList, yearPart, quarterNum, radeFiducialSet.getLessonType(), i, radeFiducialSet.getProjectsId(), radeFiducialSet.getProjectsName(), type, radeFiducialSet.getSubjectsId(), radeFiducialSet.getId(), null, yearClassId);

                            } catch (Exception ignored) {
                            }
                            break;

                        case "物理正确率":
                            try {
                                List<MathChaPlan> mathChaPlanList = iTeacherFeignClient.getPhysicsPassRadeListIFeign(null, yearPart.toString(), quarterNum.toString(), String.valueOf(type), i.toString(), i.toString(), yearClassId, null, null, "1", LocalDate.now().toString(), LocalDate.now().toString(), LocalDate.now().toString(), "3", "", "", null, null, "2", null, null, null, null, null, null, null, "2", null, null, null, null);

                                if (mathChaPlanList == null || mathChaPlanList.size() == 0) {
                                    continue;
                                }

                                List<RankedArrivalRate> rankedList = new ArrayList<>();
                                for (MathChaPlan mathChaPlan : mathChaPlanList) {
                                    BigDecimal arrivalCount = new BigDecimal(mathChaPlan.getRightNumAll());
                                    BigDecimal studentAllCount = new BigDecimal(mathChaPlan.getLowestShutnumAll());
                                    BigDecimal rade = new BigDecimal(0);
                                    if (!studentAllCount.equals(BigDecimal.ZERO)) {
                                        rade = arrivalCount.divide(studentAllCount, 4, RoundingMode.HALF_UP).multiply(new BigDecimal(100));
                                    }
                                    rankedList.add(new RankedArrivalRate(mathChaPlan.getSchoolId(), rade));
                                }

                                this.processRankedArrivalRates(rankedList, yearPart, quarterNum, radeFiducialSet.getLessonType(), i, radeFiducialSet.getProjectsId(), radeFiducialSet.getProjectsName(), type, radeFiducialSet.getSubjectsId(), radeFiducialSet.getId(), null, yearClassId);

                            } catch (Exception ignored) {
                            }
                            break;

                        case "请假补课率":
                            try {
                                List<CancellationRate> cancellationRateList = iTeacherFeignClient.cancellationRateIfeign(null, null, yearPart, quarterNum, LocalDate.now().toString(), LocalDate.now().toString(), null, null, type, yearClassId, null, i.toString(), i.toString(), null, "1", null);

                                if (cancellationRateList == null || cancellationRateList.size() == 0) {
                                    continue;
                                }

                                List<RankedArrivalRate> rankedList = new ArrayList<>();
                                for (CancellationRate cancellationRate : cancellationRateList) {
                                    BigDecimal arrivalCount = new BigDecimal(cancellationRate.getAlreadyCount());
                                    BigDecimal studentAllCount = new BigDecimal(cancellationRate.getShouldCount());
                                    BigDecimal rade = new BigDecimal(0);
                                    if (!studentAllCount.equals(BigDecimal.ZERO)) {
                                        rade = arrivalCount.divide(studentAllCount, 4, RoundingMode.HALF_UP).multiply(new BigDecimal(100));
                                    }
                                    rankedList.add(new RankedArrivalRate(cancellationRate.getSchoolId(), rade));
                                }

                                this.processRankedArrivalRates(rankedList, yearPart, quarterNum, radeFiducialSet.getLessonType(), i, radeFiducialSet.getProjectsId(), radeFiducialSet.getProjectsName(), type, radeFiducialSet.getSubjectsId(), radeFiducialSet.getId(), null, yearClassId);

                            } catch (Exception ignored) {
                            }
                            break;
                    }
                }
            }
        }

        /**
         * 成绩数据、缴费率统计
         */
        for (String yearClassId : yearClassIdList) {
            for (RadeFiducialSet radeFiducialSet : senateDepartScoreSets) {
                switch (radeFiducialSet.getProjectsName()) {
                    case "成绩数据":
                        try {
                            // 期中
                            List<ScoreData> scoreDataList1 = iTeacherFeignClient.scoreDataListIFeign(null, null, String.valueOf(yearPart), String.valueOf(quarterNum), "1", yearClassId, "0", String.valueOf(type), "5", "2", null, null, null);
                            // 期末
                            List<ScoreData> scoreDataList2 = iTeacherFeignClient.scoreDataListIFeign(null, null, String.valueOf(yearPart), String.valueOf(quarterNum), "3", yearClassId, "0", String.valueOf(type), "5", "2", null, null, null);

                            for (int examNum = 1; examNum < 4; examNum += 2) {
                                List<ScoreData> scoreDataList = new ArrayList<>();
                                if (examNum == 1) {
                                    if (scoreDataList1 == null || scoreDataList1.size() == 0) {
                                        continue;
                                    }
                                    scoreDataList = scoreDataList1;
                                } else if (examNum == 3) {
                                    if (scoreDataList2 == null || scoreDataList2.size() == 0) {
                                        continue;
                                    }
                                    scoreDataList = scoreDataList2;
                                }
                                List<RankedArrivalRate> rankedList = new ArrayList<>();
                                for (ScoreData scoreData : scoreDataList) {
                                    if (scoreData.getStuRealityCount() != 0) {
                                        // 优秀率
                                        BigDecimal passRate = new BigDecimal(scoreData.getPassCount() - scoreData.getNotCalcPassCount()).divide(new BigDecimal(scoreData.getStuRealityCount() - scoreData.getNotCalcCount()), 4, RoundingMode.HALF_UP).multiply(new BigDecimal(100));
                                        // 提分率
                                        BigDecimal carryRate = new BigDecimal(scoreData.getCarryCount()).divide(new BigDecimal(scoreData.getStuRealityCount() - scoreData.getNotCalcCount()), 4, RoundingMode.HALF_UP).multiply(new BigDecimal(100));
                                        // 安全值
                                        BigDecimal secureRate = carryRate.add(passRate);

                                        rankedList.add(new RankedArrivalRate(scoreData.getSchoolId(), secureRate));
                                    }
                                }

                                this.processRankedArrivalRates(rankedList, yearPart, quarterNum, 1, null, 11, "成绩数据", type, 0L, radeFiducialSet.getId(), examNum, yearClassId);
                            }

                        } catch (Exception ignored) {
                        }
                        break;
                    case "缴费率":
                        try {

                            List<RenewClassRecord> renewClassRecordList = iTeacherFeignClient.payFeeIFeign(null, null, yearPart, quarterNum, yearClassId, null, 1, 1, null, type, null, null, null, null, null, 0, 0, 1, 2, 1, null);

                            if (renewClassRecordList == null || renewClassRecordList.size() == 0) {
                                continue;
                            }

                            List<RankedArrivalRate> rankedList = new ArrayList<>();
                            for (RenewClassRecord renewClassRecord : renewClassRecordList) {
                                BigDecimal arrivalCount = new BigDecimal(renewClassRecord.getBigFifteen());
                                BigDecimal studentAllCount = new BigDecimal(renewClassRecord.getStudentAllCount());
                                BigDecimal rade = new BigDecimal(0);
                                if (!studentAllCount.equals(BigDecimal.ZERO)) {
                                    rade = arrivalCount.divide(studentAllCount, 4, RoundingMode.HALF_UP).multiply(new BigDecimal(100));
                                }
                                rankedList.add(new RankedArrivalRate(renewClassRecord.getSchoolId(), rade));
                            }

                            this.processRankedArrivalRates(rankedList, yearPart, quarterNum, 1, null, radeFiducialSet.getProjectsId(), radeFiducialSet.getProjectsName(), type, radeFiducialSet.getSubjectsId(), radeFiducialSet.getId(), null, yearClassId);

                        } catch (Exception ignored) {
                        }
                        break;
                }
            }
        }


    }


    /**
     * 率的基准值计算方法
     *
     * @param rankedList
     * @param yearPart     年份
     * @param quarterNum   季度
     * @param lessonType   课程类型
     * @param lessonNum    课次
     * @param projectsId   项目id
     * @param projectsName 项目名字
     */
    public void processRankedArrivalRates(List<RankedArrivalRate> rankedList, Integer yearPart, Integer quarterNum, Integer lessonType, Integer lessonNum, Integer projectsId, String projectsName, Integer type, Long subjectsId, Long fiducialSetId, Integer examNum, String yearClassId) {

        if (rankedList == null || rankedList.size() == 0) {
            return;
        }

        rankedList.sort((a, b) -> b.getRade().compareTo(a.getRade()));

        HashMap<Long, Integer> rankingMap = new HashMap<>();
        int currentRank = 0;
        BigDecimal lastRade = null;
        for (int rank = 0; rank < rankedList.size(); rank++) {
            RankedArrivalRate current = rankedList.get(rank);
            if (lastRade == null || lastRade.compareTo(current.getRade()) != 0) {
                currentRank = rank + 1;
            }
            rankingMap.put(current.getSchoolId(), currentRank);
            lastRade = current.getRade();
        }

        StringBuilder radeStr = new StringBuilder();
        for (RankedArrivalRate rankedArrivalRate : rankedList) {
            // 保留两位小数四舍五入
            BigDecimal rade = rankedArrivalRate.getRade().setScale(2, RoundingMode.HALF_UP);
            radeStr.append(rade).append(",");

//            // 保存到rade_data表中
//            RadeData radeData = new RadeData();
//            radeData.setYearPart(yearPart);
//            radeData.setQuarterNum(quarterNum);
//            radeData.setSchoolId(rankedArrivalRate.getSchoolId());
//            radeData.setLessonType(lessonType);
//            radeData.setProjectsId(projectsId);
//            radeData.setStatType(type);
//            radeData.setRadeNum(rade);
//            Integer rank = rankingMap.get(rankedArrivalRate.getSchoolId());
//            radeData.setRankNum(rank);
//            radeData.setExamNum(examNum);
//            radeData.setFiducialSetId(fiducialSetId);
//            if (lessonNum != null) {
//                radeData.setLessonNum(lessonNum);
//            }
//            if (subjectsId != null) {
//                radeData.setSubjectsId(subjectsId);
//            }
//            if (StringUtils.isNotBlank(yearClassId)) {
//                radeData.setYearClassId(Integer.valueOf(yearClassId));
//            }
//            iSenateScoreService.addOrUpdateRadeData(radeData);
        }

        radeStr.deleteCharAt(radeStr.length() - 1);

        if (rankedList.size() > 1) {
            rankedList.remove(0);
            rankedList.remove(rankedList.size() - 1);
        }

        BigDecimal average = new BigDecimal(0);
        for (RankedArrivalRate rankedArrivalRate : rankedList) {
            average = average.add(rankedArrivalRate.getRade());
        }
        average = average.divide(new BigDecimal(rankedList.size()), 2, RoundingMode.HALF_UP);

        RadeFiducial radeFiducial = new RadeFiducial();
        radeFiducial.setYearPart(yearPart);
        radeFiducial.setQuarterNum(quarterNum);
        radeFiducial.setLessonType(lessonType);
        radeFiducial.setSubjectsId(subjectsId);
        radeFiducial.setProjectsId(projectsId);
        radeFiducial.setProjectsName(projectsName);
        radeFiducial.setLessonNum(lessonNum);
        radeFiducial.setRadeNum(average);
        radeFiducial.setRadeAll(String.valueOf(radeStr));
        radeFiducial.setFiducialSetId(fiducialSetId);
        iSenateScoreService.addOrUpdateRadeFiducialData(radeFiducial);

    }

    /**
     * 数据汇总
     */
    @Override
    public void dataStatisticsAction(IntegralStatisticsRs integralStatisticsRs) {
        Integer yearPart = integralStatisticsRs.getYearPart();
        Integer quarterNum = integralStatisticsRs.getQuarterNum();

        Integer startLessonNum = 0;
        Integer endLessonNum = 0;
        LocalDate dateNow = LocalDate.now();

        if (integralStatisticsRs.getStartLessonNum() != null && integralStatisticsRs.getEndLessonNum() != null) {
            startLessonNum = integralStatisticsRs.getStartLessonNum();
            endLessonNum = integralStatisticsRs.getEndLessonNum();
        } else {
            Integer lessonMax = iRecordCourseService.getMaxLessonNumForInClass(yearPart, quarterNum, 1);
            if (lessonMax != null) {
                startLessonNum = 1;
                endLessonNum = lessonMax;
            }
        }

        QueryWrapper<RadeFiducialSet> radeFiducialSetQueryWrapper = new QueryWrapper<>();
        radeFiducialSetQueryWrapper.eq("year_part", yearPart);
        radeFiducialSetQueryWrapper.eq("quarter_num", quarterNum);
        radeFiducialSetQueryWrapper.eq("status", 1);
        List<RadeFiducialSet> senateDepartScoreSets = iRadeFiducialSetService.list(radeFiducialSetQueryWrapper);

        List<Integer> typeList = new ArrayList<>();
        typeList.add(2);
        typeList.add(6);

        List<String> subjectIdList = new ArrayList<>();
        subjectIdList.add("");
        subjectIdList.add("1");
        subjectIdList.add("2");
        subjectIdList.add("3");

        List<String> yearClassIdList = new ArrayList<>();
        yearClassIdList.add(YEAR_CLASS_ID_DEFAULT);
        for (int yearClassId = 0; yearClassId < 13; yearClassId++) {
            yearClassIdList.add(String.valueOf(yearClassId));
        }

        for (Integer type : typeList) {
            for (Integer i = startLessonNum; i <= endLessonNum; i++) {
                for (String subjectId : subjectIdList) {
                    for (String yearClassId : yearClassIdList) {
                        for (RadeFiducialSet radeFiducialSet : senateDepartScoreSets) {
                            switch (radeFiducialSet.getProjectsName()) {
                                case "精品课到课率":
                                    try {
                                        List<ArrivalRate> arrivalRateList = iTeacherFeignClient.arrivalRate(type, null, subjectId, null, dateNow.toString(), dateNow.toString(), null, null, "2", null, null, yearPart.toString(), quarterNum.toString(), null, null, null, yearClassId, "1", null, i.toString(), i.toString(), null, null, "0", "0");

                                        if (arrivalRateList == null || arrivalRateList.size() == 0) {
                                            continue;
                                        }

                                        for (ArrivalRate arrivalRate : arrivalRateList) {
                                            BigDecimal arrivalCount = new BigDecimal(arrivalRate.getArrivedCount());
                                            BigDecimal studentAllCount = new BigDecimal(arrivalRate.getStudentAllCount());

                                            // 保存到rade_data表中
                                            RadeData radeData = new RadeData();
                                            radeData.setYearPart(yearPart);
                                            radeData.setQuarterNum(quarterNum);
                                            radeData.setSchoolId(arrivalRate.getSchoolId());
                                            radeData.setLessonType(1);
                                            if (StringUtils.isNotBlank(subjectId)) {
                                                radeData.setSubjectsId(Long.valueOf(subjectId));
                                            } else {
                                                radeData.setSubjectsId(0L);
                                            }
                                            if (!yearClassId.equals(YEAR_CLASS_ID_DEFAULT)) {
                                                radeData.setYearClassId(Integer.valueOf(yearClassId));
                                            }
                                            if (type == 2) {
                                                radeData.setTeacherId(arrivalRate.getTeacherId());
                                            }
                                            radeData.setFiducialSetId(radeFiducialSet.getId());
                                            radeData.setProjectsId(radeFiducialSet.getProjectsId());
                                            radeData.setLessonNum(i);
                                            radeData.setRadeMolecule(arrivalCount);
                                            radeData.setRadeDenominator(studentAllCount);
                                            radeData.setStatType(type);
                                            iSenateScoreService.addOrUpdateRadeData(radeData);

                                        }
                                    } catch (Exception ignored) {
                                    }
                                    break;
                                case "精品课准时率":
                                    try {
                                        List<ArrivalRate> arrivalRateList = iTeacherFeignClient.tardinessRateIFeign(yearPart.toString(), quarterNum.toString(), null, null, null, yearClassId, "1", i.toString(), i.toString(), null, subjectId, null, "5", "2", null, null, LocalDate.now().toString(), LocalDate.now().toString(), null, type, null, null, "0", "0");

                                        if (arrivalRateList == null || arrivalRateList.size() == 0) {
                                            continue;
                                        }

                                        for (ArrivalRate arrivalRate : arrivalRateList) {
                                            BigDecimal arrivalCount = new BigDecimal(arrivalRate.getStudentAllCount() - arrivalRate.getTardinessRateCount() - arrivalRate.getLeaveCount());
                                            BigDecimal studentAllCount = new BigDecimal(arrivalRate.getStudentAllCount());

                                            // 保存到rade_data表中
                                            RadeData radeData = new RadeData();
                                            radeData.setYearPart(yearPart);
                                            radeData.setQuarterNum(quarterNum);
                                            radeData.setSchoolId(arrivalRate.getSchoolId());
                                            radeData.setLessonType(1);
                                            if (StringUtils.isNotBlank(subjectId)) {
                                                radeData.setSubjectsId(Long.valueOf(subjectId));
                                            } else {
                                                radeData.setSubjectsId(0L);
                                            }
                                            if (!yearClassId.equals(YEAR_CLASS_ID_DEFAULT)) {
                                                radeData.setYearClassId(Integer.valueOf(yearClassId));
                                            }
                                            if (type == 2) {
                                                radeData.setTeacherId(arrivalRate.getTeacherId());
                                            }
                                            radeData.setFiducialSetId(radeFiducialSet.getId());
                                            radeData.setProjectsId(radeFiducialSet.getProjectsId());
                                            radeData.setLessonNum(i);
                                            radeData.setRadeMolecule(arrivalCount);
                                            radeData.setRadeDenominator(studentAllCount);
                                            radeData.setStatType(type);
                                            iSenateScoreService.addOrUpdateRadeData(radeData);
                                        }

                                    } catch (Exception ignored) {
                                    }
                                    break;

                                case "旷课率":
                                    try {
                                        List<ArrivalRate> arrivalRateList = iTeacherFeignClient.arrivalRate(type, null, subjectId, null, dateNow.toString(), dateNow.toString(), null, null, "2", null, null, yearPart.toString(), quarterNum.toString(), null, null, null, yearClassId, "1", null, i.toString(), i.toString(), null, null, "0", "0");

                                        if (arrivalRateList == null || arrivalRateList.size() == 0) {
                                            continue;
                                        }

                                        for (ArrivalRate arrivalRate : arrivalRateList) {
                                            BigDecimal arrivalCount = new BigDecimal(arrivalRate.getNoArrivedCount());
                                            BigDecimal studentAllCount = new BigDecimal(arrivalRate.getStudentAllCount());

                                            // 保存到rade_data表中
                                            RadeData radeData = new RadeData();
                                            radeData.setYearPart(yearPart);
                                            radeData.setQuarterNum(quarterNum);
                                            radeData.setSchoolId(arrivalRate.getSchoolId());
                                            radeData.setLessonType(1);
                                            if (StringUtils.isNotBlank(subjectId)) {
                                                radeData.setSubjectsId(Long.valueOf(subjectId));
                                            } else {
                                                radeData.setSubjectsId(0L);
                                            }
                                            if (!yearClassId.equals(YEAR_CLASS_ID_DEFAULT)) {
                                                radeData.setYearClassId(Integer.valueOf(yearClassId));
                                            }
                                            if (type == 2) {
                                                radeData.setTeacherId(arrivalRate.getTeacherId());
                                            }
                                            radeData.setFiducialSetId(radeFiducialSet.getId());
                                            radeData.setProjectsId(radeFiducialSet.getProjectsId());
                                            radeData.setLessonNum(i);
                                            radeData.setRadeMolecule(arrivalCount);
                                            radeData.setRadeDenominator(studentAllCount);
                                            radeData.setStatType(type);
                                            iSenateScoreService.addOrUpdateRadeData(radeData);
                                        }

                                    } catch (Exception ignored) {
                                    }
                                    break;

                                case "请假补课率":
                                    try {
                                        List<CancellationRate> cancellationRateList = iTeacherFeignClient.cancellationRateIfeign(null, subjectId, yearPart, quarterNum, LocalDate.now().toString(), LocalDate.now().toString(), null, null, type, yearClassId, null, i.toString(), i.toString(), null, "1", null);

                                        if (cancellationRateList == null || cancellationRateList.size() == 0) {
                                            continue;
                                        }

                                        for (CancellationRate cancellationRate : cancellationRateList) {
                                            BigDecimal arrivalCount = new BigDecimal(cancellationRate.getAlreadyCount());
                                            BigDecimal studentAllCount = new BigDecimal(cancellationRate.getShouldCount());

                                            // 保存到rade_data表中
                                            RadeData radeData = new RadeData();
                                            radeData.setYearPart(yearPart);
                                            radeData.setQuarterNum(quarterNum);
                                            radeData.setSchoolId(cancellationRate.getSchoolId());
                                            radeData.setLessonType(1);
                                            if (StringUtils.isNotBlank(subjectId)) {
                                                radeData.setSubjectsId(Long.valueOf(subjectId));
                                            } else {
                                                radeData.setSubjectsId(0L);
                                            }
                                            if (!yearClassId.equals(YEAR_CLASS_ID_DEFAULT)) {
                                                radeData.setYearClassId(Integer.valueOf(yearClassId));
                                            }
                                            if (type == 2) {
                                                radeData.setTeacherId(cancellationRate.getTeacherId());
                                            }
                                            radeData.setFiducialSetId(radeFiducialSet.getId());
                                            radeData.setProjectsId(radeFiducialSet.getProjectsId());
                                            radeData.setLessonNum(i);
                                            radeData.setRadeMolecule(arrivalCount);
                                            radeData.setRadeDenominator(studentAllCount);
                                            radeData.setStatType(type);
                                            iSenateScoreService.addOrUpdateRadeData(radeData);
                                        }

                                    } catch (Exception ignored) {
                                    }
                                    break;

                                case "英语通关率":
                                    try {
                                        if (StringUtils.isBlank(subjectId) || subjectId.equals("1")) {
                                            List<PassRade> radeList = iTeacherFeignClient.getMinimumTaskProgressRateIFeign(yearPart.toString(), quarterNum.toString(), yearClassId, null, null, type, 1, "1", null, LocalDate.now().toString(), LocalDate.now().toString(), null, null, null, "7", "2", i, i, null, null);

                                            if (radeList == null || radeList.size() == 0) {
                                                continue;
                                            }

                                            for (PassRade passRade : radeList) {
                                                BigDecimal arrivalCount = new BigDecimal(passRade.getAllStudentNum() - passRade.getNotStudentNum());
                                                BigDecimal studentAllCount = new BigDecimal(passRade.getAllStudentNum());

                                                // 保存到rade_data表中
                                                RadeData radeData = new RadeData();
                                                radeData.setYearPart(yearPart);
                                                radeData.setQuarterNum(quarterNum);
                                                radeData.setSchoolId(passRade.getSchoolId());
                                                radeData.setLessonType(2);
                                                if (StringUtils.isNotBlank(subjectId)) {
                                                    radeData.setSubjectsId(Long.valueOf(subjectId));
                                                } else {
                                                    radeData.setSubjectsId(0L);
                                                }
                                                if (!yearClassId.equals(YEAR_CLASS_ID_DEFAULT)) {
                                                    radeData.setYearClassId(Integer.valueOf(yearClassId));
                                                }
                                                if (type == 2) {
                                                    radeData.setTeacherId(passRade.getTeacherId());
                                                }
                                                radeData.setFiducialSetId(radeFiducialSet.getId());
                                                radeData.setProjectsId(radeFiducialSet.getProjectsId());
                                                radeData.setLessonNum(i);
                                                radeData.setRadeMolecule(arrivalCount);
                                                radeData.setRadeDenominator(studentAllCount);
                                                radeData.setStatType(type);
                                                iSenateScoreService.addOrUpdateRadeData(radeData);
                                            }
                                        }

                                    } catch (Exception ignored) {
                                    }
                                    break;

                                case "英语正确率":
                                    try {
                                        if (StringUtils.isBlank(subjectId) || subjectId.equals("1")) {
                                            List<PassRade> radeList = iTeacherFeignClient.getMinimumTaskProgressRateIFeign(yearPart.toString(), quarterNum.toString(), yearClassId, null, null, type, 1, "1", null, LocalDate.now().toString(), LocalDate.now().toString(), null, null, null, "7", "2", i, i, null, null);

                                            if (radeList == null || radeList.size() == 0) {
                                                continue;
                                            }

                                            for (PassRade passRade : radeList) {
                                                BigDecimal arrivalCount = new BigDecimal(passRade.getFirstRightCount());
                                                BigDecimal studentAllCount = new BigDecimal(passRade.getFirstWordCount());

                                                // 保存到rade_data表中
                                                RadeData radeData = new RadeData();
                                                radeData.setYearPart(yearPart);
                                                radeData.setQuarterNum(quarterNum);
                                                radeData.setSchoolId(passRade.getSchoolId());
                                                radeData.setLessonType(2);
                                                if (StringUtils.isNotBlank(subjectId)) {
                                                    radeData.setSubjectsId(Long.valueOf(subjectId));
                                                } else {
                                                    radeData.setSubjectsId(0L);
                                                }
                                                if (!yearClassId.equals(YEAR_CLASS_ID_DEFAULT)) {
                                                    radeData.setYearClassId(Integer.valueOf(yearClassId));
                                                }
                                                if (type == 2) {
                                                    radeData.setTeacherId(passRade.getTeacherId());
                                                }
                                                radeData.setFiducialSetId(radeFiducialSet.getId());
                                                radeData.setProjectsId(radeFiducialSet.getProjectsId());
                                                radeData.setLessonNum(i);
                                                radeData.setRadeMolecule(arrivalCount);
                                                radeData.setRadeDenominator(studentAllCount);
                                                radeData.setStatType(type);
                                                iSenateScoreService.addOrUpdateRadeData(radeData);
                                            }
                                        }

                                    } catch (Exception ignored) {
                                    }
                                    break;

                                case "数学通关率":
                                    try {
                                        if (StringUtils.isBlank(subjectId) || subjectId.equals("2")) {
                                            List<MathChaPlan> mathChaPlanList = iTeacherFeignClient.getPassRadeListIFeign(null, yearPart.toString(), quarterNum.toString(), String.valueOf(type), i.toString(), i.toString(), yearClassId, null, null, "1", LocalDate.now().toString(), LocalDate.now().toString(), LocalDate.now().toString(), "2", "", "", null, null, "1", null, null, null, null, null, null, null, "1", null, null, null, null);

                                            if (mathChaPlanList == null || mathChaPlanList.size() == 0) {
                                                continue;
                                            }

                                            for (MathChaPlan mathChaPlan : mathChaPlanList) {
                                                BigDecimal arrivalCount = new BigDecimal(mathChaPlan.getYetFinishCount2());
                                                BigDecimal studentAllCount = new BigDecimal(mathChaPlan.getShowPassNum());

                                                // 保存到rade_data表中
                                                RadeData radeData = new RadeData();
                                                radeData.setYearPart(yearPart);
                                                radeData.setQuarterNum(quarterNum);
                                                radeData.setSchoolId(mathChaPlan.getSchoolId());
                                                radeData.setLessonType(3);
                                                if (StringUtils.isNotBlank(subjectId)) {
                                                    radeData.setSubjectsId(Long.valueOf(subjectId));
                                                } else {
                                                    radeData.setSubjectsId(0L);
                                                }
                                                if (!yearClassId.equals(YEAR_CLASS_ID_DEFAULT)) {
                                                    radeData.setYearClassId(Integer.valueOf(yearClassId));
                                                }
                                                if (type == 2) {
                                                    radeData.setTeacherId(mathChaPlan.getTeacherId());
                                                }
                                                radeData.setFiducialSetId(radeFiducialSet.getId());
                                                radeData.setProjectsId(radeFiducialSet.getProjectsId());
                                                radeData.setLessonNum(i);
                                                radeData.setRadeMolecule(arrivalCount);
                                                radeData.setRadeDenominator(studentAllCount);
                                                radeData.setStatType(type);
                                                iSenateScoreService.addOrUpdateRadeData(radeData);
                                            }
                                        }

                                    } catch (Exception ignored) {
                                    }
                                    break;

                                case "数学正确率":
                                    try {
                                        if (StringUtils.isBlank(subjectId) || subjectId.equals("2")) {
                                            List<MathChaPlan> mathChaPlanList = iTeacherFeignClient.getPassRadeListIFeign(null, yearPart.toString(), quarterNum.toString(), String.valueOf(type), i.toString(), i.toString(), yearClassId, null, null, "1", LocalDate.now().toString(), LocalDate.now().toString(), LocalDate.now().toString(), "2", "", "", null, null, "2", null, null, null, null, null, null, null, "2", null, null, null, null);

                                            if (mathChaPlanList == null || mathChaPlanList.size() == 0) {
                                                continue;
                                            }

                                            for (MathChaPlan mathChaPlan : mathChaPlanList) {
                                                BigDecimal arrivalCount = new BigDecimal(mathChaPlan.getRightNumAll());
                                                BigDecimal studentAllCount = new BigDecimal(mathChaPlan.getLowestShutnumAll());

                                                // 保存到rade_data表中
                                                RadeData radeData = new RadeData();
                                                radeData.setYearPart(yearPart);
                                                radeData.setQuarterNum(quarterNum);
                                                radeData.setSchoolId(mathChaPlan.getSchoolId());
                                                radeData.setLessonType(3);
                                                if (StringUtils.isNotBlank(subjectId)) {
                                                    radeData.setSubjectsId(Long.valueOf(subjectId));
                                                } else {
                                                    radeData.setSubjectsId(0L);
                                                }
                                                if (!yearClassId.equals(YEAR_CLASS_ID_DEFAULT)) {
                                                    radeData.setYearClassId(Integer.valueOf(yearClassId));
                                                }
                                                if (type == 2) {
                                                    radeData.setTeacherId(mathChaPlan.getTeacherId());
                                                }
                                                radeData.setFiducialSetId(radeFiducialSet.getId());
                                                radeData.setProjectsId(radeFiducialSet.getProjectsId());
                                                radeData.setLessonNum(i);
                                                radeData.setRadeMolecule(arrivalCount);
                                                radeData.setRadeDenominator(studentAllCount);
                                                radeData.setStatType(type);
                                                iSenateScoreService.addOrUpdateRadeData(radeData);
                                            }
                                        }
                                    } catch (Exception ignored) {
                                    }
                                    break;

                                case "物理通关率":
                                    try {
                                        if (StringUtils.isBlank(subjectId) || subjectId.equals("3")) {
                                            List<MathChaPlan> mathChaPlanList = iTeacherFeignClient.getPhysicsPassRadeListIFeign(null, yearPart.toString(), quarterNum.toString(), String.valueOf(type), i.toString(), i.toString(), yearClassId, null, null, "1", LocalDate.now().toString(), LocalDate.now().toString(), LocalDate.now().toString(), "3", "", "", null, null, "1", null, null, null, null, null, null, null, "1", null, null, null, null);

                                            if (mathChaPlanList == null || mathChaPlanList.size() == 0) {
                                                continue;
                                            }

                                            for (MathChaPlan mathChaPlan : mathChaPlanList) {
                                                BigDecimal arrivalCount = new BigDecimal(mathChaPlan.getYetFinishCount2());
                                                BigDecimal studentAllCount = new BigDecimal(mathChaPlan.getShowPassNum());

                                                // 保存到rade_data表中
                                                RadeData radeData = new RadeData();
                                                radeData.setYearPart(yearPart);
                                                radeData.setQuarterNum(quarterNum);
                                                radeData.setSchoolId(mathChaPlan.getSchoolId());
                                                radeData.setLessonType(3);
                                                if (StringUtils.isNotBlank(subjectId)) {
                                                    radeData.setSubjectsId(Long.valueOf(subjectId));
                                                } else {
                                                    radeData.setSubjectsId(0L);
                                                }
                                                if (!yearClassId.equals(YEAR_CLASS_ID_DEFAULT)) {
                                                    radeData.setYearClassId(Integer.valueOf(yearClassId));
                                                }
                                                if (type == 2) {
                                                    radeData.setTeacherId(mathChaPlan.getTeacherId());
                                                }
                                                radeData.setFiducialSetId(radeFiducialSet.getId());
                                                radeData.setProjectsId(radeFiducialSet.getProjectsId());
                                                radeData.setLessonNum(i);
                                                radeData.setRadeMolecule(arrivalCount);
                                                radeData.setRadeDenominator(studentAllCount);
                                                radeData.setStatType(type);
                                                iSenateScoreService.addOrUpdateRadeData(radeData);
                                            }
                                        }

                                    } catch (Exception ignored) {
                                    }
                                    break;

                                case "物理正确率":
                                    try {
                                        if (StringUtils.isBlank(subjectId) || subjectId.equals("3")) {
                                            List<MathChaPlan> mathChaPlanList = iTeacherFeignClient.getPhysicsPassRadeListIFeign(null, yearPart.toString(), quarterNum.toString(), String.valueOf(type), i.toString(), i.toString(), yearClassId, null, null, "1", LocalDate.now().toString(), LocalDate.now().toString(), LocalDate.now().toString(), "3", "", "", null, null, "2", null, null, null, null, null, null, null, "2", null, null, null, null);

                                            if (mathChaPlanList == null || mathChaPlanList.size() == 0) {
                                                continue;
                                            }

                                            for (MathChaPlan mathChaPlan : mathChaPlanList) {
                                                BigDecimal arrivalCount = new BigDecimal(mathChaPlan.getRightNumAll());
                                                BigDecimal studentAllCount = new BigDecimal(mathChaPlan.getLowestShutnumAll());

                                                // 保存到rade_data表中
                                                RadeData radeData = new RadeData();
                                                radeData.setYearPart(yearPart);
                                                radeData.setQuarterNum(quarterNum);
                                                radeData.setSchoolId(mathChaPlan.getSchoolId());
                                                radeData.setLessonType(3);
                                                if (StringUtils.isNotBlank(subjectId)) {
                                                    radeData.setSubjectsId(Long.valueOf(subjectId));
                                                } else {
                                                    radeData.setSubjectsId(0L);
                                                }
                                                if (!yearClassId.equals(YEAR_CLASS_ID_DEFAULT)) {
                                                    radeData.setYearClassId(Integer.valueOf(yearClassId));
                                                }
                                                if (type == 2) {
                                                    radeData.setTeacherId(mathChaPlan.getTeacherId());
                                                }
                                                radeData.setFiducialSetId(radeFiducialSet.getId());
                                                radeData.setProjectsId(radeFiducialSet.getProjectsId());
                                                radeData.setLessonNum(i);
                                                radeData.setRadeMolecule(arrivalCount);
                                                radeData.setRadeDenominator(studentAllCount);
                                                radeData.setStatType(type);
                                                iSenateScoreService.addOrUpdateRadeData(radeData);
                                            }
                                        }

                                    } catch (Exception ignored) {
                                    }
                                    break;
                            }
                        }
                    }
                }
            }
        }

        /**
         * 成绩数据、缴费率统计
         */
        for (Integer type : typeList) {
            for (String subjectId : subjectIdList) {
                for (String yearClassId : yearClassIdList) {
                    for (RadeFiducialSet radeFiducialSet : senateDepartScoreSets) {
                        switch (radeFiducialSet.getProjectsName()) {
                            case "成绩数据":
                                try {
                                    // 期中
                                    List<ScoreData> scoreDataList1 = iTeacherFeignClient.scoreDataListIFeign(null, subjectId, String.valueOf(yearPart), String.valueOf(quarterNum), "1", yearClassId, "0", String.valueOf(type), "5", "2", null, null, null);
                                    processScoreDataList(scoreDataList1, 1, yearClassId, subjectId, type, yearPart, quarterNum);

                                    // 期末
                                    List<ScoreData> scoreDataList2 = iTeacherFeignClient.scoreDataListIFeign(null, subjectId, String.valueOf(yearPart), String.valueOf(quarterNum), "3", yearClassId, "0", String.valueOf(type), "5", "2", null, null, null);
                                    processScoreDataList(scoreDataList2, 3, yearClassId, subjectId, type, yearPart, quarterNum);

                                } catch (Exception ignored) {
                                }
                                break;

                            case "缴费率":
                                try {
                                    List<RenewClassRecord> renewClassRecordList = iTeacherFeignClient.payFeeIFeign(null, null, yearPart, quarterNum, yearClassId, null, 1, 1, subjectId, type, null, null, null, null, null, 0, 0, 1, 2, 1, null);

                                    if (renewClassRecordList == null || renewClassRecordList.size() == 0) {
                                        continue;
                                    }

                                    for (RenewClassRecord renewClassRecord : renewClassRecordList) {
                                        BigDecimal arrivalCount = new BigDecimal(renewClassRecord.getBigFifteen());
                                        BigDecimal studentAllCount = new BigDecimal(renewClassRecord.getStudentAllCount());

                                        // 保存到rade_data表中
                                        RadeData radeData = new RadeData();
                                        radeData.setYearPart(yearPart);
                                        radeData.setQuarterNum(quarterNum);
                                        radeData.setSchoolId(renewClassRecord.getSchoolId());
                                        radeData.setLessonType(1);
                                        if (StringUtils.isNotBlank(subjectId)) {
                                            radeData.setSubjectsId(Long.valueOf(subjectId));
                                        } else {
                                            radeData.setSubjectsId(0L);
                                        }
                                        if (!yearClassId.equals(YEAR_CLASS_ID_DEFAULT)) {
                                            radeData.setYearClassId(Integer.valueOf(yearClassId));
                                        }
                                        if (type == 2) {
                                            radeData.setTeacherId(renewClassRecord.getTeacherId());
                                        }
                                        radeData.setFiducialSetId(radeFiducialSet.getId());
                                        radeData.setProjectsId(radeFiducialSet.getProjectsId());
                                        radeData.setRadeMolecule(arrivalCount);
                                        radeData.setRadeDenominator(studentAllCount);
                                        radeData.setStatType(type);
                                        iSenateScoreService.addOrUpdateRadeData(radeData);
                                    }
                                } catch (Exception ignored) {
                                }
                                break;
                        }
                    }
                }
            }
        }


    }

    /**
     * 成绩数据统计
     */
    private void processScoreDataList(List<ScoreData> scoreDataList, Integer examNum, String yearClassId, String
            subjectId, Integer type, Integer yearPart, Integer quarterNum) {
        if (scoreDataList == null || scoreDataList.size() == 0) {
            return;
        }

        for (ScoreData scoreData : scoreDataList) {
            if (scoreData.getStuRealityCount() != 0) {
                RadeData radeData = new RadeData();
                radeData.setYearPart(yearPart);
                radeData.setQuarterNum(quarterNum);
                radeData.setSchoolId(scoreData.getSchoolId());
                if (StringUtils.isNotBlank(subjectId)) {
                    radeData.setSubjectsId(Long.valueOf(subjectId));
                } else {
                    radeData.setSubjectsId(0L);
                }
                if (StringUtils.isNotBlank(yearClassId) && !yearClassId.equals(YEAR_CLASS_ID_DEFAULT)) {
                    radeData.setYearClassId(Integer.valueOf(yearClassId));
                }
                radeData.setLessonType(1);
                radeData.setTeacherId(scoreData.getTeacherId());
                radeData.setFiducialSetId(14L);
                radeData.setProjectsId(11);
                radeData.setStatType(type);
                radeData.setExamNum(examNum);

                // 优秀率
//                BigDecimal passRate = new BigDecimal(scoreData.getPassCount() - scoreData.getNotCalcPassCount()).divide(new BigDecimal(scoreData.getStuRealityCount() - scoreData.getNotCalcCount()), 4, RoundingMode.HALF_UP).multiply(new BigDecimal(100));
                // 提分率
//                BigDecimal carryRate = new BigDecimal(scoreData.getCarryCount()).divide(new BigDecimal(scoreData.getStuRealityCount() - scoreData.getNotCalcCount()), 4, RoundingMode.HALF_UP).multiply(new BigDecimal(100));
                // 安全值
//                BigDecimal secureRate = carryRate.add(passRate);

                radeData.setRadeMolecule(BigDecimal.valueOf(scoreData.getPassCount() - scoreData.getNotCalcPassCount()));
                radeData.setRadeDenominator(BigDecimal.valueOf(scoreData.getStuRealityCount() - scoreData.getNotCalcCount()));

                radeData.setRadeMolecule02(BigDecimal.valueOf(scoreData.getCarryCount()));
                radeData.setRadeDenominator02(BigDecimal.valueOf(scoreData.getStuRealityCount() - scoreData.getNotCalcCount()));

                iSenateScoreService.addOrUpdateRadeData(radeData);
            }
        }
    }

}
